Changing Resource files (resx) namespace and access modifier

为君一笑 提交于 2019-12-02 17:23:42

I'm not entirely sure where the problem lies yet, but I can tell you that you can solve it by changing the tool used to generate the code.

When I tried to follow this article, I also stumbled onto this problem. After downloading the source files as the author suggested, I noticed that the resource file that were already present had the following class in the "Custom Tool" property: "PublicResXFileCodeGenerator". Also, the "Build Action" property was set to "Embedded Resource", but I'm not sure if that's part of the problem.

Any new resource file that I created used the custom tool "GlobalResourceProxyGenerator". After overwriting this with the aforementioned "PublicResXFileCodeGenerator" seemed to solve the problem, whatever the real problem may be.

I also noticed that the present resource file was in the "2.0" format, whereas new files were in the "1.3" format. You can see this when you open the resx file using an XML editor (or by using "open with" from visual studio itself).

I hope you can make it work like this, it's not ideal though. It's likely to be an installation issue with Visual Studio 2008 and SP1, or something like that.

Update:

This blog entry may also help.

Mark Bonafe

The quick answer is: Just open the Properties of the resource file and change the Custom Tool Namespace to the namespace you need.
Simple as that.

Joost Schepel

Or you can change the CustomTool attribute (tested in VS2010).

You just have to open the file properties of the resource file and change the “Custom Tool” from “GlobalResourceProxyGenerator” to “PublicResXFileCodeGenerator”, which is the default Tool for local resource files. Next you have to change the “Build Action” to “Embedded Resource”. You may also want to assign a proper Custom Tool Namespace like “Resources” in order to access the file properly, but this isn’t necessary...

Source

The resx picks up the namespace depending on the namespace specified in your Visual Studio project configuration. Update your project to have the right namespace, and the resx should inherit it (new ones for sure, not sure if existing ones will be fixed - they should).

Resource Files access modifiers are in the .csproj;

Changing directly the .csproj file should workaround this problem.

Look for the <Generator> element and set its value in accordance to the examples below:

A resource file with internal modifier looks like this,

<ItemGroup>
 <EmbeddedResource Update="resources.resx">
  <Generator>ResXFileCodeGenerator</Generator>
  <LastGenOutput>resources.Designer.cs</LastGenOutput>
 </EmbeddedResource>
</ItemGroup>

where a resource file with public modifier looks like this.

<ItemGroup>
 <EmbeddedResource Update="resources.resx">
  <Generator>PublicResXFileCodeGenerator</Generator>
  <LastGenOutput>resources.Designer.cs</LastGenOutput>
 </EmbeddedResource>
</ItemGroup>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!