Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What / why is Roslyn "needed" in /bin folder of Asp.Net

There are a bunch of related questions on this, though most of the answers define Roslyn and/or provide a "fix" to some issue (exe, with hosting providers, etc.)

What I can't seem to track down is the "why" and "what for" (perhaps only in the context of ASP.Net MVC/Web API) in /bin/roslyn.

I ran in to similar issues (hosting - .exe restrictions, support for 4.6, etc.) and my "fix" was to "just deploy to Azure" (of course everything works without a hitch). But really, this doesn't answer:

  • why are they needed?
  • does this mean that the they are used for runtime compilation (my brain points to this, but that is a complete guess/my perhaps wrong grok), as this SO post shows - unless corrected, this is "it" (more below).
  • it seems "removing the package" is a "fix" (based on some past answers), but if so, it (re)begs the question

I think understanding this will help - e.g. I can't be the only one who will have an eyebrow raised seeing an .exe "needed"....


Update

Goes to show that "hidden gems" exist :) I've read this over and over...after all it's been there for some time now - but not the comments thread - the original referenced link, circa 2014, has been redesigned by Microsoft and the comments are no longer displayed...luckily the relevant parts are below.

BIG mistake - it was staring at me all this time (or at least since this exchange):

Dmitry Dzygin 2 Jun 2015 12:53 AM

I have tried the latest version of the NuGet package, but there's seem to be a difference in the way the compiler is loaded/executed.

In the v0.2.0.0 the Roslyn compiler would be loaded into memory, improving greatly performance for not pre-compiled websites with multiple *.as*x/*.cshtml files. The new version, however, features a new /bin/roslyn/csc.exe file, which is executed once per file, completely removing the mentioned above optimization feature.....

Gold:

XMao 2 Jun 2015 1:22 PM

@Dmitry The job of the csc.exe in /bin/Roslyn is to invoke the VBCSCompiler.exe, which sits in the same folder. VBCSCompiler.exe is the process that does the actual compilation work. If the VBCSCompiler is already running csc.exe will reuse it and thus we will still gain the mentioned performance improvement.

Hth...


Update: 10/2017

Seems this is relevant after all this time so a further update.

The answer below by @Donny V is an option. By fully compiling your application, including all Views (.cshtml/.vbhtml), you wouldn't need that exe in your application.

This is true even if Visual Studio (to this day, VS 2017, confusingly) will still create the /bin/roslyn and it's contents in the Publish process, even if "full compile" is set.

You can test this by excluding the /bin/roslyn folder and it's contents when pushing your application to your hosting provider.

Caveat:

As mentioned, fully compiling your application means you'll have to recompile it, even for View level changes.

like image 726
EdSF Avatar asked Nov 16 '15 16:11

EdSF


People also ask

What is Roslyn used for?

Roslyn is an open source platform, developed by Microsoft, containing compilers and tools for parsing and analysis of code written in C# and Visual Basic. Roslyn is used in the Microsoft Visual Studio 2015 environment.

What is Roslyn in .NET core?

Roslyn, the . NET Compiler Platform, empowers the C# compiler on . NET Core and allows developers to leverage the rich code analysis APIs to perform code generation, analysis and compilation.


2 Answers

This is taken from MSDN forum.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/442b100a-2b88-4ac4-b655-0c1345791f15/roslyn-cscexe-web-api-2-on-hosting-server?forum=msbuild

I have noticed a minor drawback to uninstalling this package:

https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Some of the new C# 6.0 language features if used in Views (MVC project) will not compile. Many of my views use the ?. null checking operator for accessing Model properties. All of these views now return errors on my Godaddy hosted MVC 5 application.

This error occurs because Views (by default) are compiled at runtime using the .NET pipeline (not pre-compiled).

To resolve this issue, simply uncheck the "Allow precompiled site to be updatable" option in your publish profile settings. This should pre-compile your views and allow your C# 6.0 (Latest version of Roslyn Compiler) to run like a champ.

Just wanted anyone looking at this question to know the ramification of uninstalling it and why its there in the first place

like image 90
Donny V. Avatar answered Oct 12 '22 10:10

Donny V.


Was running into this issue all the time in Visual Studio 2017 Community Edition where the project could not be rebuilt because the older files in bin/roslyn could not be deleted. Based on the OP's Gold comment, I now keep the Task Manager open (Ctrl+Shift+Esc) and kill the VBCS.exe process. The offending files in bin/roslyn can now be deleted.

like image 21
Manish Avatar answered Oct 12 '22 12:10

Manish