-addmodule(C# 编译器选项)-addmodule (C# Compiler Options)

此选项将添加一个模块,该模块通过将 target: module 切换到当前编译进行创建。This option adds a module that was created with the target:module switch to the current compilation.




filefile2file, file2
包含元数据的输出文件。An output file that contains metadata. 该文件不能包含程序集清单。The file cannot contain an assembly manifest. 若要导入多个文件,请用逗号或分号将文件名隔开。To import more than one file, separate file names with either a comma or a semicolon.


通过 -addmodule 添加的所有模块在运行时必须位于与输出文件相同的目录中。All modules added with -addmodule must be in the same directory as the output file at run time. 也就是说,在编译时可在任何目录中指定模块,但在运行时该模块必须位于应用程序目录中。That is, you can specify a module in any directory at compile time but the module must be in the application directory at run time. 如果在运行时该模块不位于应用程序目录中,则将出现 TypeLoadExceptionIf the module is not in the application directory at run time, you will get a TypeLoadException.

file 不能包含程序集。file cannot contain an assembly. 例如,如果输出文件使用 -target:module 创建,其元数据可通过 -addmodule 导入。For example, if the output file was created with -target:module, its metadata can be imported with -addmodule.

如果输出文件通过使用 -target 选项而不是 -target:module 创建,则其元数据不能通过 -addmodule 导入,但可以通过 -reference 导入。If the output file was created with a -target option other than -target:module, its metadata cannot be imported with -addmodule but can be imported with -reference.

此编译器选项在 Visual Studio 中不可用;项目不能引用模块。This compiler option is unavailable in Visual Studio; a project cannot reference a module. 此外,不能以编程方式更改此编译器选项。In addition, this compiler option cannot be changed programmatically.


编译源文件 input.cs,并从 metad1.netmodulemetad2.netmodule 添加元数据以生成 out.exeCompile source file input.cs and add metadata from metad1.netmodule and metad2.netmodule to produce out.exe:

csc -addmodule:metad1.netmodule;metad2.netmodule -out:out.exe input.cs  

请参阅See also