XML 序列化程序生成器工具 (Sgen.exe)XML Serializer Generator Tool (Sgen.exe)

XML 序列化器生成器为指定程序集中的类型创建 XML 序列化程序集。The XML Serializer Generator creates an XML serialization assembly for types in a specified assembly. 序列化程序集在序列化或取消序列化XmlSerializer指定类型的对象时提高了 启动性能。The serialization assembly improves the startup performance of a XmlSerializer when it serializes or deserializes objects of the specified types.

语法Syntax

从命令行运行该工具。Run the tool from the command line.

sgen [options]  

提示

对于 .NET 框架工具要正常运行,必须正确设置Path IncludeLib和环境变量。For .NET Framework tools to function properly, you must set your Path, Include, and Lib environment variables correctly. 可以通过运行 SDKVars.bat(位于 <SDK>\v2.0\Bin 目录中)来设置这些环境变量。Set these environment variables by running SDKVars.bat, which is located in the <SDK>\v2.0\Bin directory. 必须在每个命令 shell 程序中执行 SDKVars.bat。SDKVars.bat must be executed in every command shell.

参数Parameters

选项Option 描述Description
/ssembly[]:文件名/a[ssembly]:filename 为由 filename 指定的程序集或可执行文件中包含的所有类型生成序列化代码**。Generates serialization code for all the types contained in the assembly or executable specified by filename. 只能提供一个文件名。Only one file name can be provided. 如果该参数重复,将使用最后一个文件名。If this argument is repeated, the last file name is used.
/c[欧皮]勒 :选项/c[ompiler]:options 指定要传递给 C# 编译器的选项。Specifies the options to pass to the C# compiler. 支持所有传递到编译器的 csc.exe 选项。All csc.exe options are supported as they are passed to the compiler. 这可用于指定应该对程序集进行签名,以及用于指定密钥文件。This can be used to specify that the assembly should be signed and to specify the key file.
/d[ebug]/d[ebug] 生成一个可用于调试器的映像。Generates an image that can be used with a debugger.
/f[奥尔塞]/f[orce] 强制覆盖同名的现有程序集。Forces the overwriting of an existing assembly of the same name. 默认值为falseThe default is false.
/帮助或/?/help or /? 显示该工具的命令语法和选项。Displays command syntax and options for the tool.
/k[eep]/k[eep] 取消在生成的源文件和其他临时文件编译到序列化程序集内之后对它们的删除操作。Suppresses the deletion of the generated source files and other temporary files after they have been compiled into the serialization assembly. 这可用于确定工具是否正在为某个特定类型生成序列化代码。This can be used to determine whether the tool is generating serialization code for a particular type.
/n[奥洛戈]/n[ologo] 取消显示 Microsoft 启动版权标志。Suppresses the display of the Microsoft startup banner.
/o[]ut :路径/o[ut]:path 指定要在其中保存生成的程序集的目录。Specifies the directory in which to save the generated assembly. 注意: 生成的程序集的名称由输入程序集的名称加上“xmlSerializers.dll”组成。Note: The name of the generated assembly is composed of the name of the input assembly plus "xmlSerializers.dll".
/p[罗西型]/p[roxytypes] 仅生成 XML Web services 代理类型的序列化代码。Generates serialization code only for the XML Web service proxy types.
/r[efers]:程序集文件/r[eference]:assemblyfiles 指定由需要 XML 序列化的类型引用的程序集。Specifies the assemblies that are referenced by the types requiring XML serialization. 接受多个程序集文件(由逗号分隔)。Accepts multiple assembly files separated by commas.
/s[ilent]/s[ilent] 取消显示成功消息。Suppresses the display of success messages.
/t[]ype :类型/t[ype]:type 仅生成指定类型的序列化代码。Generates serialization code only for the specified type.
/v[erbose]/v[erbose] 显示详细输出,以进行调试。Displays verbose output for debugging. 列出目标程序集中无法使用 XmlSerializer 进行序列化的类型。Lists types from the target assembly that cannot be serialized with the XmlSerializer.
/?/? 显示该工具的命令语法和选项。Displays command syntax and options for the tool.

备注Remarks

不使用 XML 序列化程序生成器时,XmlSerializer 在应用程序每次运行时为每个类型生成序列化代码和一个序列化程序集。When the XML Serializer Generator is not used, a XmlSerializer generates serialization code and a serialization assembly for each type every time an application is run. 为了提高 XML 序列化启动的性能,请使用 Sgen.exe 工具提前生成这些程序集。To improve the performance of XML serialization startup, use the Sgen.exe tool to generate those assemblies in advance. 然后可以使用应用程序部署这些程序集。These assemblies can then be deployed with the application.

XML 序列化程序生成器还可以改进使用 XML Web services 代理与服务器通信的客户端的性能,因为在第一次加载类型时,序列化进程将不会导致性能受损。The XML Serializer Generator can also improve the performance of clients that use XML Web service proxies to communicate with servers because the serialization process will not incur a performance hit when the type is loaded the first time.

这些生成的程序集无法在 Web 服务的服务器端使用。These generated assemblies cannot be used on the server side of a Web service. 该工具仅能用于 Web 服务客户端和手动序列化方案。This tool is only for Web service clients and manual serialization scenarios.

如果包含要序列化的类型的程序集名为 MyType.dll,则关联的序列化程序集的名称将为 MyType.XmlSerializers.dll。If the assembly containing the type to serialize is named MyType.dll, then the associated serialization assembly will be named MyType.XmlSerializers.dll.

示例Examples

下面的命令创建一个名为 Data.XmlSerializers.dll 的程序集,用于序列化名为 Data.dll 的程序集中包含的所有类型。The following command creates an assembly named Data.XmlSerializers.dll for serializing all the types contained in the assembly named Data.dll.

sgen Data.dll

可以从代码中引用需要序列化和反序列化 Data.dll 中的类型的 Data.XmlSerializers.dll 程序集。The Data.XmlSerializers.dll assembly can be referenced from code that needs to serialize and deserialize the types in Data.dll.

请参阅See also