Resource File Generator (Resgen.exe)
The Resource File Generator converts .txt files and .resx (XML-based resource format) files to common language runtime binary .resources files that can be embedded in a runtime binary executable or compiled into satellite assemblies. For information about deploying and retrieving .resources files, see Resources in Applications.
Resgen.exe performs the following conversions:
- Converts .txt files to .resources or .resx files.
- Converts .resources files to text or .resx files.
- Converts .resx files to text or .resources files.
resgen [/compile] filename.extension [outputFilename.extension][...]
Argument | Description |
---|---|
filename.extension | The name of the input file to convert. The extension must be one of the following:
|
outputFilename.extension | The name of the resource file to create.
This argument is optional when converting from a .txt or .resx file. You can specify the .resources extension when converting a text or .resx file to a .resources file. If you do not specify an outputFilename, Resgen.exe appends a .resources extension to the input filename argument and writes the file to the directory that contains filename. The outputFilename argument is mandatory when converting from a .resources file. Specify the .resx extension when converting a .resources file to an XML-based resource file. Specify the .txt extension when converting a .resources file to a text file. You should only convert a .resources file to a .txt file when the .resources file contains only string values. |
Option | Description |
---|---|
/compile | Allows you to specify multiple .resx or .txt files to convert to .resources files in a single bulk operation. If you do not specify this option, you can specify only one input file argument. |
Remarks
Resgen.exe converts files by wrapping the methods implemented by the following four classes:
- ResourceReader Class Reads a .resources file.
- ResourceWriter Class Creates a .resources file from specified resources.
- ResXResourceReader Class Reads a .resx file.
- ResXResourceWriter Class Creates a .resx file from specified resources.
Note that a .resx file created by the ResXResourceWriter 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:
name=value
Resgen.exe checks the text file for duplicate resource 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.
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.
Examples
The following command, with no options specified, displays the command syntax and options for Resgen.exe.
resgen
The following command reads the name/value pairs in myResources.txt
and writes a binary resources file named myResources.resources
. Because the output file name is not specified explicitly, it receives the same name as the input file by default.
resgen myResources.txt
The following command reads the name/value pairs in myResources.txt
and writes a binary resources file named yourResources.resources
.
resgen myResources.txt yourResources.resources
The following command reads an XML-based input file myResources.resx
and writes a binary resources file named myResources.resources
.
resgen myResources.resx myResources.resources
The following command reads a binary resources file myResources.resources
and writes an XML-based output file named myResources.resx
.
resgen myResources.resources myResources.resx
The following command reads an XML-based input file myResources.resx
and writes a .txt file named myResources.txt
. Note that if the .resx file contains any embedded objects, they will not be accurately converted into the .txt file.
resgen myResources.resx myResources.txt
See Also
.NET Framework Tools | Resources in Applications | Developing World-Ready Applications | Assembly Linker (Al.exe)