views:

352

answers:

1

In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated Strings.Designer.cs file.

Tracking the Strings.Designer.cs file in source control creates a bunch of ugly merge conflicts and it's autogenerated anyway, so we decided to untrack it (remove it from source control and ignore the local copy of the file).

This works well, except that on a fresh checkout of the source the Strings.Designer.cs file doesn't exist. The PublicResXFileCodeGenerator that generates the file from Strings.resx balks with a warning:

"The custom tool 'PublicResXFileCodeGenerator' failed while processing the file 'Views\Setup\App_LocalResources\Strings.resx'."

And as a result, all of the strings in that file generate compile errors. This means you must manually right-click on each Strings.resx file in the project and choose "Run Custom Tool".

Is there any way to get the ResX code generator tool to run automatically even if Strings.Designer.cs doesn't yet exist?

(We've experimented with ResGen but it is finicky--it refuses to generate Strings files with the proper filename and namespace.)

+1  A: 

You can use ResGen.exe to explicitly regenerate the .resources and .Designer.cs files from your .resx. Just throw a command that looks something like the following into your prebuild events:

ResGen.exe Strings.resx NameSpace.Strings.resources /publicClass /str:cs,"Your.Namespace",Strings,Strings.Designer.cs

...which will generate a Your.Namespace.Strings.resources file and a Strings.Designer.cs file w/ a "Strings" class in the "Your.Namespace" namespace.

(The /publicClass switch tells ResGen to generate public members, and "cs" is the C# language choice.)

Read more here: http://msdn.microsoft.com/en-us/library/ccec7sz1(VS.80).aspx

kamens