Omit localized versions of assemblies from the build output
Asked Answered
D

2

29

In one of my projects, I am using an awesome library called Humanizer. This library comes in many language variations (I counted 38).

When I build my project, I then see all these folders like "af", "ar", "bg", "bn-BD", ..., "zh-Hant" with assemblies containing the localized resources for this library.

My issue is that my project is English-only and I have no interest in having all those localized assemblies in my build output. Is there some good way of omitting them from the build?

I am looking for general solutions to this problem. It happens with libraries other than Humanizer, like DevExpress Controls etc., which are not open-source.

Danica answered 15/5, 2015 at 14:51 Comment(1)
Humanizer 2.0 now allows you to choose which localization packages you want. If you only need English then you can just install the Humanizer.Core package. You can read more about this here - github.com/Humanizr/Humanizer#specify-languages-optionalFlirt
C
21

With the latest msbuild you can simply put this into your .csproj file:

<PropertyGroup>
  <SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
</PropertyGroup>

See dotnet/sdk/issues/774

Charil answered 29/1, 2020 at 0:58 Comment(0)
R
37

What you can do is add a target (here, I named it 'RemoveSatelliteAssemblies') to the msbuild .csproj project file, for example, at the end:

<Project...>
  ....
  <Target Name="RemoveSatelliteAssemblies" AfterTargets="ResolveAssemblyReferences">
    <ItemGroup>
        <ReferenceCopyLocalPaths Remove="@(ReferenceSatellitePaths)" />
    </ItemGroup>
  </Target>
</Project>

This target will run after the standard ResolveAssemblyReferences target (defined somewhere in a Microsoft.Common[something].targets file in the C:\Program Files (x86)\MSBuild directory or in the C:\Windows\Microsoft.Net directory - it depends on your Visual Studio / MsBuild setups and versions), and it will remove all reference satellite paths from the list of referenced paths marked as copy local (both ItemGroup names are also declared in the standard .targets file).

Rage answered 20/5, 2015 at 9:5 Comment(5)
This works for me too. We include the SSRS Report Viewer in some of our projects, and this has many satellite assemblies that we do not need.Rhebarhee
Note, that this removes all localization files, even those referenced from your other projectsInterbreed
This is outdated!Charil
@Charil - no, it depends on the version of MSBuild, Visual Studio, etc. you use.Rage
Ok, correction: This is outdated since .NET versions from 2018!Charil
C
21

With the latest msbuild you can simply put this into your .csproj file:

<PropertyGroup>
  <SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
</PropertyGroup>

See dotnet/sdk/issues/774

Charil answered 29/1, 2020 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.