Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

c# - Omit localized versions of assemblies from the build output

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:WindowsMicrosoft.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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...