GenerateResource Task
Converts between .txt and .resx (XML-based resource format) files and common language runtime binary .resources files that can be embedded in a runtime binary executable or compiled into satellite assemblies. This task is typically used to convert .txt or .resx files to .resource files. The GenerateResource task is functionally similar to resgen.exe.
Parameters
The following table describes the parameters of the GenerateResource task.
Parameter |
Description |
---|---|
FilesWritten |
Optional ITaskItem[] output parameter. Contains the names of all files written to disk. This includes the cache file, if any. This parameter is useful for implementations of Clean. |
OutputResources |
Optional ITaskItem[] output parameter. Specifies the name of the generated files, such as .resources files. If you do not specify a name, the name of the matching input file is used and the .resources file that is created is placed in the directory that contains the input file. |
PublicClass |
Optional Boolean parameter. If true, creates a strongly typed resource class as a public class. |
References |
Optional String[] parameter. References to load types in .resx files from. Resx file data elements may have a .NET type. When the .resx file is read, this must be resolved. Typically, it is resolved successfully by using standard type loading rules. If you provide assemblies in References, they take precedence. This parameter is not required for strongly typed resources. |
Sources |
Required ITaskItem[] parameter. Specifies the items to convert. Items passed to this parameter must have one of the following file extensions:
|
StateFile |
Optional ITaskItem parameter. Specifies the path to an optional cache file that is used to speed up dependency checking of links in .resx input files. |
StronglyTypedClassName |
Optional String parameter. Specifies the class name for the strongly typed resource class. If this parameter is not specified, the base name of the resource file is used. |
StronglyTypedFilename |
Optional ITaskItem parameter. Specifies the filename for the source file. If this parameter is not specified, the name of the class is used as the base filename, with the extension dependent on the language. For example: MyClass.cs. |
StronglyTypedLanguage |
Optional String parameter. Specifies the language to use when generating the class source for the strongly typed resource. This parameter must match exactly one of the languages used by the CodeDomProvider. For example: VB or C#. By passing a value to this parameter, you instruct the task to generate strongly typed resources. |
StronglyTypedNamespace |
Optional String parameter. Specifies the namespace to use for the generated class source for the strongly typed resource. If this parameter is not specified, any strongly typed resources are in the global namespace. |
UseSourcePath |
Optional Boolean parameter. If true, specifies that the input file's directory is to be used for resolving relative file paths. |
Remarks
Because .resx files may contain links to other resource files, it is not sufficient to simply compare .resx and .resource file timestamps to see if the outputs are up-to-date. Instead, the GenerateResource task follows the links in the .resx files and checks the timestamps of the linked files as well. This means that you should not generally use Inputs and Outputs attributes on the target containing the GenerateResource task, as this may cause it to be skipped when it should actually run.
Example
The following example uses the GenerateResource task to generate .resources files from the files specified by the Resx item collection.
<GenerateResource
Sources="@(Resx)"
OutputResources="@(Resx->'$(IntermediateOutputPath)%(Identity).resources')">
<Output
TaskParameter="OutputResources"
ItemName="Resources"/>
</GenerateResource>
The GenerateResource task uses the <LogicalName> metadata of an <EmbeddedResource> item to name the resource that is embedded in an assembly.
Assuming that the assembly is named myAssembly, the following code generates an embedded resource named someQualifier.someResource.resources:
<ItemGroup> <EmbeddedResource Include="myResource.resx"> <LogicalName>someQualifier.someResource.resources</LogicalName> </EmbeddedResource></ItemGroup>
Without the <LogicalName> metadata, the resource would be named myAssembly.myResource.resources. This example applies only to the Visual Basic and Visual C# build process.