开发者

Embedded Resource missing in Visual Studio 2010 when name ends with "No.xxx"

I've come across a strange behaviour in Visual Studio 2010.

When using embedded resources (files which are added to my C# project and for which the Build Action property is set to Embedded Resource), the files are included in the output assembly as binary data. Listing the resources is straightforward:

class Program
{
    static void Main(string[] args)
    {
        string[] names = typeof (Program).A开发者_Go百科ssembly.GetManifestResourceNames ();

        foreach (var name in names)
        {
            System.Console.Out.WriteLine (name);
        }
    }
}

However, if the embedded resource file name ends with No.xxx (the extension is irrelevant), the file does not show up in the list. I cannot figure out any reason why Visual Studio 2010 would not include such a file. What did I miss?

Note: if I rename the embedded resource file in the solution explorer to something else, then everything works as expected.


Dan from the Microsoft Connect team has finally provided a valid explanation for this behaviour:

Hello, thanks for the report, this is actually working normally. The reason is that any resx files whose names match the pattern .VALIDCULTURE.resx are assumed to be specific to that culture. (This is how it has worked since VS2002, for better or worse) In your case "no" is a valid culture (Norwegian, I guess) so the build process builds it into a satellite assembly. Here's what I got when I tried this. Note the "no" subfolder. If in your app you change your current culture to Norwegian, the resource load will load this set of resources.

So the problem has nothing to do with the word No itself, but rather with the fact that it is a valid, two-letter, culture name (in my case Norwegian). I checked, and indeed, there was a sub-folder in bin\Debug named No, containing a satellite assembly named Project.resources.dll in it.

Renaming the resource to end with .EN.xxx or .FR.xxx does, of course, exhibit the same behaviour.


As of MSBuild 16.9 you can include files like these by setting the WithCulture property to "false", as pointed out by @reduckted :-)

<EmbeddedResource Include="Resources.en.xml" WithCulture="false" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜