I'm publishing an ASP.NET Core MVC 3.0 website and the output folder contains lots of reference in many language to Microsoft.CodeAnalysis
librairies, someone knows why?
Of course the FxCopAnalyzers
Nuget package is installed on the project, but it was not published in an earlier version of the project, so I don't understand why it is now since it should be useful only at dev time not in a production environment.
For me, this line inside
*.csproj
file solved the issue somehow. It still deploys theMicrosoft.CodeAnalysis
, but only foren
:See the comment (by Jonathon Marolf) on the Github issue.
Here's my take at trying to make the solution easier to see.
The problem, more than likely is use of
AddRazorRuntimeCompilation()
. More specifically, in the startup.cs you likely to add razor runtime compilation like so:and to support that, your web project probably has a reference to
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
That nuget package has a dependency on
Microsoft.CodeAnalysis
that is producing all that unwanted output in the publish folder.The fix is to edit the project file and make the dependency conditional on Debug mode like so:
and then in the startup.cs file conditionally call
AddRazorRuntimeCompilation()
like so:This will cause all those
Microsoft.CodeAnalysis
librairies to only be out when compiling in Debug mode. So now when you publish using Release mode they will not be part of the output.I did encounter the same issue when I used the 3.0 version. But I don't think it's caused by .net core 3 compiling views on publication because there's also View ViewCompilation in the
release/2.1
branch .I believe you're correct. These Analysis should be used at devtime only.
But when I uninstall the SDK(3.0) manually and install the latest SDK again, I can't not reproduce any more. I don't why it happens, maybe it has been fixed now. It is more likely caused by another reason: I added an extra reference on other packages that depends on Microsoft.CodeAnalysis by accident). Anyway, please upgrade your SDK to the latest version firstly.
Another important thing is, when using Visual Studio to add controller, it will add a reference on
Microsoft.VisualStudio.Web.CodeGeneration.Design
automatically. Note this package has a dependency onMicrosoft.CodeAnalysis.Common
package indirectly. Here theMicrosoft.CodeAnalysis.Common
is a shared package used by the Microsoft .NET Compiler Platform ("Roslyn"). If you download this package and unzip this lib manually, you'll find that there's aMicrosoft.CodeAnalysis.dll
:This package is only needed at Dev-Time. If you don't remove this dependency, you'll get quite a lot of dlls related to
Microsoft.CodeAnalysis
in your publish folder.Remove those packages that depends on
Microsoft.CodeAnalysis
, and then you should get noMicrosoft.CodeAnalysis
related dlls: