Thursday, February 25, 2016

How to solve roslyn compiler issue on shared hosting?

Scenario:
I have created a web application using Visual Studio 2015 and .NET 4.6. When I have compiled and uploaded my project files to the hosting server, it showed the exception of related to permission. After checking for a while I found that application is trying to execute the CSC.exe file within the Bin\roslyn\ folder, but IIS user account does not permission to do that.

Solution:
If you are trying to publish Roslyn on shared hosting then you should know that it runs on Full Trust mode. Shared hosting companies does not allow Full Trust applications automatically , they override this globally with Medium Trust due to security restrictions as they are hosting multiple customers website and they don’t want one application affects another by any chance. Some hosting provider provide you the control to run your application on Full trust and provide setting to do that in these days.

Roslyn compilation will only work with Full Trust so on some shared hosting you might face challenges. I would suggest ask your hosting provider if they support Full Trust mode or not.

If shared hosting does not support Full Trust you should not deploy application with Roslyn, this will display you some sort of .exe file missing errors. Even you can’t upload .exe files to FTP on shared server, but you can somehow able to upload these exe files through their control using the zip package and then unzip on the hosting folder.

Below are the steps to deploy without Roslyn:

  1. Open NuGet Package Manager from tools menu or Use Manage NuGet Packages for Solution it will give you graphical way to uninstall packages from the solution project in which you are using that package.

    clip_image002_thumb[1]
  2. Now uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform package using the below command line in Package Manager console:

    Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform <Your Web project name>

    clip_image004_thumb[2]
  3. Now rebuild & republish. This uninstallation also removes CodeDom configuration from web.config file. This will solve your purpose. Basically this will not generate any csc.exe, vbc.exe files inside bin folder of your project.

    In your web project publish profile settings, uncheck "Allow precompiled site to be updatable". You can find this under Settings > Precompile during publishing > configure.

    clip_image005_thumb[3]

Solution from - Roslyn CSC.exe, Web API 2 on Hosting Server
Hope this help others to solve the issue.
Cheers!

No comments :

Post a Comment