Why is Microsoft.CodeAnalysis published with ASP.NET Core website?

dotnet publish
dotnet core include dependencies
uninstall microsoft codeanalysis
net core dependency tree
dotnet publish test project
dotnet build vs publish
dotnet publish clean
dotnet publish task

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.


contains lots of reference in many language to Microsoft.CodeAnalysis librairies

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 .


it should be useful only at dev time not in a production environnement.

  1. I believe you're correct. These Analysis should be used at devtime only.

  2. 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.

  3. 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 on Microsoft.CodeAnalysis.Common package indirectly. Here the Microsoft.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 a Microsoft.CodeAnalysis.dll :

    microsoft.codeanalysis.common.3.3.1/
    ├───lib/
    │   └───netstandard2.0/
    │       ├─── ...
    │       ├─── Microsoft.CodeAnalysis.dll
    │       ├─── Microsoft.CodeAnalysis.pdb
    │       ├─── Microsoft.CodeAnalysis.xml
    │       └─── ...
    ├───package/
    │   └───...
    └───_rels/
    

    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.

    <ItemGroup>
        <!-- this is not necessary when publishing -->
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
    </ItemGroup>
    

    Remove those packages that depends on Microsoft.CodeAnalysis, and then you should get no Microsoft.CodeAnalysis related dlls:

dotnet/roslyn, nefcanto commented on Oct 25, 2019. After upgrading to .NET Core 3.0, based on this issue I had to replace RazorViewEngineOptions  Needs More Info (Publish Includes Many Microsoft.CodeAnalysis.resources.dll) #16028 cgountanis opened this issue Dec 4, 2019 · 15 comments · Fixed by #16034 Assignees


For me, this line inside *.csproj file solved the issue somehow. It still deploys the Microsoft.CodeAnalysis, but only for en:

<PropertyGroup>
  <!-- ... -->
  <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>

See the comment (by Jonathon Marolf) on the Github issue.

.NET Core, ASP.NET Core provides the web app development features used by .NET Core Azure: Microsoft-prefixed Azure integration packages removed A migration guide was published to migrate code using this CodeAnalysis )  When I publish an ASP.NET Core 3.0 project, I get a few localized folders where the 4 assemblies shown are in each of these folders. I am not sure why these folders and files get included. None of my packages reference a CodeAnalysis package.


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:

     IMvcBuilder builder = services.AddControllersWithViews()
                          .AddRazorRuntimeCompilation(); 

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:

    <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" 
Version="3.1.0" Condition="'$(Configuration)' == 'Debug'" />
  </ItemGroup>

and then in the startup.cs file conditionally call AddRazorRuntimeCompilation() like so:

    IMvcBuilder builder = services.AddControllersWithViews();

     #if DEBUG
            if (Env.IsDevelopment()) {
                builder.AddRazorRuntimeCompilation();
            }
      #endif

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.

ASP.NET Core breaking changes, NET Core 2.2, follow the guidance in the obsolete build messages to NET Web Forms and MVC can be adapted to ASP. A migration guide was published to migrate code using this CodeAnalysis )  Sample ASP.NET Core 3.1 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder. 4.6K


Maybe this can help someone, in my case the problem was "Microsoft.VisualStudio.Web.CodeGeneration.Desig", I needed to change the package reference in ".csproj" file to include ExcludeAssets="all":

<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" ExcludeAssets="All" />

Breaking changes, version 2.2 to 3.0, NET Compiler Platform ("Roslyn"). This is the all-in-one package (a superset of all assemblies). You can install any of these sub-packages if you only want part  Why is Microsoft retiring C# and ASP.Net Core exams 70-486 and others. I do understand Microsoft is moving towards Role Based Certification. However, none of the Role Based Developer Certification has any mention of .Net Core or C#.


Microsoft.CodeAnalysis 3.6.0, Why do visual studio generate a lot of localized files about code analysis in the publish folder when I publish an asp.net core site? These localized files are not  Publishing your ASP.NET Core application There are lots of options for hosting your .NET Core application, especially now you can choose linux and take advantage of potentially cheaper hosting. Whatever you choose, a useful first step is figuring out how to package up your app so you can publish it to your chosen host.


Why do visual studio generate a lot of localized files about code , Created by Microsoft, a set of analyzers, called Microsoft.CodeAnalysis.​FxCopAnalyzers, that contains the most important “FxCop” rules from  Publishing an app as self-contained includes the .NET Core runtime with the app, and users of the app don't have to worry about installing .NET Core before running the app. Apps published as runtime-dependent don't include the .NET Core runtime and libraries; only the app and 3rd-party dependencies are included.


Top 10 Static Code Quality Analysers for ASP.NET Core, CodeAnalysis 3.3.1 requires Microsoft. Web -> Telerik.UI.for.AspNet.Core 2019.3.1023 -> Microsoft. for ASP.NET Core Visual Studio extensions Based on the written in the blog post "Visual Studio" 16.4.0 comes with . By default, the publishing process creates a framework-dependent deployment, which is a type of deployment where the published application runs on machine that has the .NET Core runtime installed. Users can run the published app by double-clicking the executable or issuing the dotnet HelloWorld.dll command from a command prompt.