Dan Rigsby - Coding Up Style

.Net, C#, & Wcf Development

Making "Public" Resources Files: PublicResxFileCodeGenerator

Posted by Dan Rigsby on March 27th, 2008

This is probably one of my favorite minor additions to Visual Studio 2008, that you probably haven heard of. 

In previous versions of Visual Studio, if you created strongly typed resources files, all of the properties were “internal”.  If you wanted to expose these properties outside of the assembly, you ran into issues.  You could use a custom tool such as ResxFileCodeGeneratorEx, but that meant that each developer had to have this tool installed and you would manually have to change the custom tool name in the properties window for the resource file:

Properties

You could also make the properties public by running resgen.exe with the /publicClass attribute, but you could not do this directly through Visual Studio.  You would have to create a pre-build event to call resgen like this:

resgen.exe "myfile.rex" /publicClass /str:c#

Now, in Visual Studio 2008 there is another option which should basically make these other options obsolete.  When you are working on the strongly typed resource file, there is a new drop down list at the top of the designer that allows you to change the access modifier to either “internal” or “public”.  This will cause the strongly typed resource “code behind” file to generate properties with the selected access modfier.

Resources

You could also manually set the custom tool to use this new generator in the properties window like so:

Properties2

All of these tools and procedures generate a code behind file (typically named something like resources.designer.cs) that contains the strongly typed resource information.  This file is automatically generated by Visual Studio when the resource file itself is changed.  If you were to go in and change the resource.resx file inside of a text editor, the strongly typed code file would not reflect these changes unless you ran resgen.exe afterwards, or opened the project again in Visual Studio.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>