Why is Microsoft.CodeAnalysis published with ASP.NET Core website?
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.
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.