原文件链接:http://msdn.microsoft.com/zh-cn/library/ccec7sz1.aspx

   

 

应用程序中的资源。

Resgen.exe 执行下列转换:

  • 将 .txt 或 .restext 文件转换为 .resources 或 .resx 文件。

    注意

    但是,.restext 扩展名可帮助您更加轻松地识别包含资源定义的文本文件。

  • 将 .resources 文件转换为文本文件或 .resx 文件。

  • 将 .resx 文件转换为文本文件或 .resources 文件。

在命令提示处,键入下列命令:

resgen [parameters] [/compile]filename.extension [outputFilename.extension] [/str:lang[,namespace[,class[,file]]]]

参数

说明

filename.extension

extension 必须为下列扩展名之一:

.txt 或 .restext

文本文件只能包含字符串资源。

.resx

指定要转换为 .resources 文件或文本(.txt 或 .restext)文件的基于 XML 的资源文件的扩展名。

.resources

指定要转换为 .resx 文件或文本(.txt 或 .restext)文件的资源文件的扩展名。

outputFilename.extension

要创建的资源文件的名称。

filename 的目录中。

只有当 .resources 文件仅包含字符串值时,才应将 .resources 文件转换为 .txt 文件。

选项

说明

/compile

如果不指定此选项,则只能指定一个输入文件参数。

/str: 选项一起使用。

/publicClass

作为公共类创建强类型的资源类。

/str: 选项,则忽略此选项。

assembly

assembly 中的类型。

language[,namespace[,classname[,filename]]]

filename 选项可指定类文件的名称。

注意
filename

/compile 选项一起使用。

要避免这种情况,可同时指定类名和输出文件名。

/usesourcepath

指定输入文件的当前目录将被用于解析相对文件路径。

Resgen.exe 通过包装由下列四类实现的方法来转换文件:

  • ResourceReader 类读取 .resources 文件。

  • ResourceWriter 类从指定的资源创建 .resources 文件。

  • ResXResourceReader 类读取 .resx 文件。

  • ResXResourceWriter 类从指定的资源创建 .resx 文件。

有关在代码中实现这些类的更多信息,请参见它们各自的参考主题。

为了使 Resgen.exe 能够分析输入,文本文件和 .resx 文件遵循正确的格式是非常关键的。

必须在每行上分别指定每个名称/值对,如下例所示:

name=value

例如:

EmptyString=

例如,Resgen.exe 在处理没有使用 UTF-8 或 Unicode 编码的文本文件时将移除扩展 ANSI 字符。

文本文件格式的资源。

.Resx 文件格式中的资源。

在转换过程中将丢失嵌入的对象,并且 Resgen.exe 在检索资源时将报告有错误发生。

此类提供了对所处理文件中可用资源的强类型只读访问。

Resgen.exe(资源文件生成器) 工具生成输出文件后,重命名名称不兼容的输出文件。

程序集链接器 (Al.exe) 将资源嵌入运行时二进制可执行文件或者将其编译为附属程序集。

注意

如果出于某种原因 Resgen.exe 失败,则返回值将为 –1。

注意

VerifyResourceName

当未指定选项时,下列命令显示 Resgen.exe 的命令语法和选项。

resgen

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 

yourResources.resources 的二进制资源文件。

resgen myResources.restext yourResources.resources

myResources.resources 的二进制资源文件。

resgen myResources.resx myResources.resources

myResources.resx 的基于 XML 的输出文件。

resgen myResources.resources myResources.resx

请注意,如果 .resx 文件包含任何嵌入对象,则这些嵌入对象不会准确地转换为文本文件。

resgen myResources.resx myResources.txt
resgen myResources.resx myResources.restext

Namespace1 的命名空间中。

resgen myResources.resx myResources.resources /str:C#,Namespace1,MyClass,MyFile.cs

 

相关文章: