46

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.

I added <PreserveCompilationContext>false</PreserveCompilationContext> in the csproj file but it didn't help. Is there a way to exclude them?

enter image description here

enter image description here

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
  • Hey maybe this can help you https://stackoverflow.com/a/58298619/9358386 – Kinjal Parmar Nov 02 '19 at 06:08
  • 1
    Does this answer your question? [Why is Microsoft.CodeAnalysis published with ASP.NET Core website?](https://stackoverflow.com/questions/58291135/why-is-microsoft-codeanalysis-published-with-asp-net-core-website) – mrmowji Jan 12 '20 at 11:05

3 Answers3

44

Add this:

<SatelliteResourceLanguages>en</SatelliteResourceLanguages>

to the .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
  </PropertyGroup>

As suggested, you can use none to exclude all of them:

    <SatelliteResourceLanguages>none</SatelliteResourceLanguages>

and taking consideration languages do you want like english and spanish:

<SatelliteResourceLanguages>en;es</SatelliteResourceLanguages>

Works with VS2019 and other versions

UPDATE 2021/2022:

Still working with Visual Studio 2022 and .NET 6

      <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
      </PropertyGroup>
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
20

You get a lot of language folders containing CodeAnalysis.dll files in your published output if you have a project reference to Microsoft.VisualStudio.Web.CodeGeneration.Design, which is needed for scaffolding controllers. If that is true for your project, change the package reference in your .csproj file to include ExcludeAssets="all"

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

For example, old *.csproj file

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UserSecretsId>aspnet-foo-4E53EF45-B3BE-4943-81BE-2449DC5AA2BC</UserSecretsId>
    <BlazorLinkOnBuild>false</BlazorLinkOnBuild>
  </PropertyGroup>
  
  <ItemGroup>
    <!-- ... -->
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design"
                      Version="3.0.0" />
  </ItemGroup>
  
  <ItemGroup>
    <!-- ... -->
  </ItemGroup>
</Project>

New file *.csproj should be

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UserSecretsId>aspnet-foo-4E53EF45-B3BE-4943-81BE-2449DC5AA2BC</UserSecretsId>
    <BlazorLinkOnBuild>false</BlazorLinkOnBuild>
  </PropertyGroup>
  
  <ItemGroup>
    <!-- ... -->
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design"
                      Version="3.0.0"
                      ExcludeAssets="All" />
  </ItemGroup>
  
  <ItemGroup>
    <!-- ... -->
  </ItemGroup>
</Project>
Pang
  • 9,564
  • 146
  • 81
  • 122
Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • 7
    Hello, my application uses asp net core 3 and I added * .csproj ExcludeAssets = "All", but this did not work. Any other ideas?) – al.koval Dec 02 '19 at 09:40
  • @al.koval clean and build, or delete bin folder with your release, build again. – Andrej Lucansky Dec 11 '19 at 15:59
  • 3
    I experience the same issue. I even tried to delete Microsoft.VisualStudio.Web.CodeGeneration.Design reference completely. I still have this litter in the deployment folder. Deleting bin folder exct. does not help. Doy you have any other idea? – Ali Erdoğan Jan 06 '20 at 14:43
  • Had same problem with core 3.1, tried every solution here and still stuck with those folders. – Carl Verret Jun 18 '20 at 16:58
  • @CarlVerret Please check my answer, is for ASP .NET Core 3.1 – Leandro Bardelli Apr 14 '21 at 11:05
13

In my case, the source of these localized folders was from the package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation. It has a dependency on Microsoft.CodeAnalysis.Razor. You can read more about the purpose of the package here: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.1

You cannot just exclude an asset when trying to take advantage of the package. My work-around was to conditionally include the package reference whenever the project is in debug mode. conditional package reference

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

I then used an #if pre-processor directive to conditionally run the code that enables razor runtime compilation. pre-processor directive razor runtime compilation

#if DEBUG
            services.AddRazorPages().AddRazorRuntimeCompilation();
#else
            services.AddRazorPages();
#endif

Please note: You may need to delete your bin folder to see the folders removed after a build. Also, make sure you are building under the correct solution configuration.

I was able to find a Github issue describing this exact scenario, but unfortunately it was never resolved. https://github.com/dotnet/extensions/issues/2247

Sha
  • 2,185
  • 1
  • 36
  • 61
kangaroosky
  • 168
  • 1
  • 5
  • 1
    Doesn't work in VS2019 with Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation and services.AddControllersWithViews().AddRazorRuntimeCompilation(); – Leandro Bardelli Dec 29 '20 at 19:05
  • This is a workaround for not specifying which satellite resources you require from dependencies. I'd opt for specifying them: https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#satelliteresourcelanguages – Zimano Aug 30 '22 at 09:31
  • @Zimano I posted that answer 2 years ago. See my answer. – Leandro Bardelli Dec 14 '22 at 04:07