Search code examples
c#model-view-controllerglobalizationembedded-resourceresx

Generating Resx files for MVC


We use resx files for globalization, along with database lookups for things that can be configured (such as tab names, which can be different by product) by our CS staff, and thus aren't known at design-time.

I created a custom tool that reads resx files and intelligently dumps the key/value pairs into a relational database (matching values so we don't have duplicates).

This has been a big help to our business - we don't have to send each resx for translation (and pay for duplicate translations of shared words) and we have a 'gold standard' with all our translations (in the database).

The tool I created also reads the database, picking up the key/value pairs and the translations of each value, and creates text files for each resx file (and each language's translation of the text file) and automates running resgen.exe, a command-line tool that ships with Visual Studio, to compile the resx files from the generated text files.

I don't have any source-control integration, so we have to manually check out the resx files and manually check-in the generated files when using the tool, but this hasn't been a big problem.

My problem is that this method is failing for our new MVC projects: the MVC projects require the resx files to be embedded resources with the Access Modifier of 'public'.

Thusfar, we have been fixing this by hand, which introduces the possibility of human error and adds a non-trivial amount of work.

Is there a way to get resgen.exe to create resource files that are embedded and public? If not, is there another way I can create resx files that will do so?

Update, additional question: The resx files we generate with this method also raise a warning:

A custom tool 'PublicResXFileCodeGenerator' is associated with file '(resxname)',
but the output of the custom tool was not found in the project.
You may try re-running the custom tool by right-clicking on the file in the
Solution Explorer and choosing Run Custom Tool. 

The tool mentioned is the tool we initially use to create the resx files. Is there a way I can prevent this warning?


Solution

  • We did end up finding a solution to this problem.

    For MVC projects, we changed the tool to use the ResXResourceWriter class to update the resx files, matching existing keys and adding new ones as needed.

    This preserves the 'Embedded Resource' status as well as all of the other details that are needed.

    We still have to set the file up correctly the first time it's created, but that is a much more manageable problem.