VS2015 has been launched and if you’re using .NET Framework 4.5.2 to create projects using VS2015, you might have noticed that the project templates use Roslyn by default. If you’re not aware of Roslyn, it is a set of open-source compilers and code analysis APIs for C# and Visual Basic .NET languages from Microsoft. You can see the code here.
Many hosting providers still have not upgraded their servers and hence do not support Roslyn. This is quite common in shared hosting servers. If you upload a project with Roslyn references, you will get unwanted errors on the website. To resolve this issue, we will need to remove Roslyn from the project template. We will see how this can be done in this post.
It’s a 2 step-process to remove Roslyn from your project –
- Remove Nuget Packages:
“Microsoft.CodeDom.Providers.DotNetCompilerPlatform” & “Microsoft.Net.Compilers".
- Cleanup web.config file.
To remove Nuget packages, use the following commands from Nuget Package Console:
Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Uninstall-package Microsoft.Net.Compilers
After you do this, your web.config file should be auto-updated. In case it is not, look for the below code in web.config file and if it is found, delete this piece of code.
- <system .codedom>
- <compilers>
- <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"></compiler>
- <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"></compiler>
- </compilers>
- </system>
Build your project and upload to the server. The errors related to Roslyn should be gone.
Hope this post helps you! Cheers!