开发者

c# warning - Mark assemblies with NeutralResourcesLanguageAttribute

I'm getting the following warning:

CA1824 Mark assemblies with NeutralResourcesLanguageAttribute

According to MSDN, the cause of this is:

An assembly contains a ResX-based resource but does not have the System.Resources.NeutralResourcesLanguageAttribute applied to it.

Could anyone please explain what it means?

I don't want to define a开发者_高级运维 specific cultural setting.

I want them to be customisable.


The NeutralResourcesLanguageAttribute informs the resource manager of the language that was used to display resources which are contained in the main assembly. E.g. if you coded your assembly so that it contains resources which are in English, then include the following line in your AssemblyInfo.cs

[assembly: NeutralResourcesLanguage("en")]

This way, when looking up resources in English, the resource manager will not look for an English culture satellite assembly, but rather just use the resources contained in the main assembly. This is purely a performance optimisation.


The NeutralResourcesLanguage attribute tells the resource manager about the language used in your neutral resources (the resources whose filename don't have a culture code suffix, e.g. YourModule.resx). That information can be used during the resource fallback process.


as above, in AssemblyInfo.cs add (if not already there)

using System.Resources;

then

[assembly: NeutralResourcesLanguage("en")]


The previous answers explain how to fix the AssemblyInfo.cs file, but if you don't have one, you can do it directly on your CSPROJ file (both in .NET or .NET Core):

<PropertyGroup>
  <NeutralLanguage>en</NeutralLanguage>
</PropertyGroup>


Explanation

I think the documentation explains this very well

The NeutralResourcesLanguageAttribute attribute informs the resource manager of an app's default culture.
If the default culture's resources are embedded in the app's main assembly, and ResourceManager has to retrieve resources that belong to the same culture as the default culture, the ResourceManager automatically uses the resources located in the main assembly instead of searching for a satellite assembly.
This bypasses the usual assembly probe, improves lookup performance for the first resource you load, and can reduce your working set.

Solutions

mentioned in other answers, but to summarize

  1. using AssemblyInfo.cs file

    [assembly: NeutralResourcesLanguage("en")]
    
  2. OR in the .csproj file

    <PropertyGroup>
       <NeutralLanguage>en</NeutralLanguage>
    </PropertyGroup>
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜