Resgen.exe converts files by wrapping the methods implemented by the following four classes:
Note that a .resx file created by the ResXResourceWriter class cannot be used directly by a .NET Framework application. Before adding this file to your application, run it through Resgen.exe to convert it to a .resources file. For more information about implementing these classes in your code, see their respective reference topics.
In order for Resgen.exe to be able to parse your input, it is critical that your .txt and .resx files follow the correct format.
Text files can only contain string resources. String resources are useful if you are writing an application that must have strings translated into several languages. For example, you can easily regionalize menu strings by using the appropriate string resource. Resgen.exe reads text files containing name/value pairs, where the name is a string that describes the resource and the value is the resource string itself. You must specify each name/value pair on a separate line as follows:
Note that empty strings are permitted in text files. For example:
A text file must be saved with UTF8 or Unicode encoding, unless it contains only characters in the plain Roman alphabet, without diacritical marks such as the cedilla, umlaut, and tilde. For example, Resgen.exe removes extended ANSI characters when it processes a text file that does not have UTF8 or Unicode encoding.
Resgen.exe checks the text file for duplicate resource names. If the text file contains duplicate resource names, Resgen.exe will emit a warning and ignore the duplicate names. For more details on the text file format, see Resources in Text File Format.
The .resx resource file format consists of XML entries. Similar to .txt files, you can specify string resources within these XML entries. A primary advantage of .resx files over .txt files is that you can also specify or embed objects. When you view a .resx file, you can actually see the binary form of an embedded object (a picture for example) when this binary information is a part of the resource manifest. Just as with .txt files, you can open a .resx file with a text editor (such as Notepad or Microsoft Word) and write, parse, and manipulate the contents. Note that in order to do this, a good knowledge of XML tags and the .resx file structure is required. For more details on the .resx file format, see Resources in .Resx File Format.
In order to create a .resources file containing embedded nonstring objects, you must either use Resgen.exe to convert a .resx file containing objects or add the object resources to your file directly from code, using the methods provided by the ResourceWriter Class. If you use Resgen.exe to convert a .resources file containing objects to a .txt file, all the string resources will be converted correctly, but the data types of the nonstring objects will also be written to the file as strings. You will lose the embedded objects in the conversion and Resgen.exe will report that an error occurred in retrieving the resources.
The .NET Framework version 2.0 supports strongly-typed resources. Strongly-typed resource support encapsulates access to resources by creating classes that contain a set of static read-only (get) properties, thus providing an alternative way to consume resources, rather than using the methods of the ResourceManager class directly. The basic functionality is provided by the /str command line option in Resgen.exe, which wraps the functionality of the StronglyTypedResourceBuilder class. When you specify the /str option, the output of Resgen.exe is a class that contains strongly-typed properties that match the resources that are referenced in the input parameter. This class provides strongly-typed read-only access to the resources that are available in the file processed.
The Resource File Generator (Resgen.exe) tool allows you to create .resources files as well as strongly typed wrappers to access those .resources files. When you create a strongly typed wrapper, the name of your .resources file must match the namespace and class name (for example, MyNamespace.MyClass.resources) of the generated code. However, the Resource File Generator (Resgen.exe) tool allows you to specify options that produce a .resources file with an incompatible name. To work around this behavior, rename incompatibly named output files after the Resource File Generator (Resgen.exe) tool generates them.
When you are finished creating .resources files with Resgen.exe, use the Assembly Linker (Al.exe) to either embed the resources in a runtime binary executable or compile them into satellite assemblies.
Note |
|---|
| If Resgen.exe fails for any reason, the return value will be –1. |
Note |
|---|
| Resgen.exe does not accept a .resx file name that contains spaces when generating a strongly-typed resource class. It replaces all invalid characters with an underscore ("_"). For more information, see VerifyResourceName. |