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

-target 编译器选项可指定为以下四种形式之一:The -target compiler option can be specified in one of four forms:

创建 Windows 8.x 应用商店Windows 8.x Store应用的 .exe 文件。To create an .exe file for Windows 8.x 应用商店Windows 8.x Store apps.

创建 .exe 文件。To create an .exe file.

创建代码库。To create a code library.

创建模块。To create a module.

创建 Windows 程序。To create a Windows program.

创建一个 .winmdobj 中间文件。To create an intermediate .winmdobj file.

如果不指定 -target:module,-target 会将 .NET Framework 程序集清单放入输出文件中。Unless you specify -target:module, -target causes a .NET Framework assembly manifest to be placed in an output file. 有关详细信息,请参阅公共语言运行时中的程序集公共特性For more information, see Assemblies in the Common Language Runtime and Common Attributes.

程序集清单放置在编译中的第一个 .exe 输出文件中,如果没有 .exe 输出文件,会放置在第一个 DLL 中。The assembly manifest is placed in the first .exe output file in the compilation or in the first DLL, if there is no .exe output file. 例如,在以下的命令行中,清单将放置在 1.exe 中:For example, in the following command line, the manifest will be placed in 1.exe:

csc -out:1.exe t1.cs -out:2.netmodule t2.cs  

编译器每次编译只创建一个程序集清单。The compiler creates only one assembly manifest per compilation. 关于编译中所有文件的信息都放在程序集清单中。Information about all files in a compilation is placed in the assembly manifest. 除用 -target:module 创建的文件之外,所有输出文件都可包含程序集清单。All output files except those created with -target:module can contain an assembly manifest. 在命令行生成多个输出文件时,只能创建一个程序集清单,且该清单必须放置在命令行上指定的第一个输出文件中。When producing multiple output files at the command line, only one assembly manifest can be created and it must go into the first output file specified on the command line. 无论第一个输出文件是什么(-target:exe、-target:winexe、-target:library 或 -target:module),在同一编译中生成的任何其他输出文件都必须是模块 (-target:module)。No matter what the first output file is (-target:exe, -target:winexe, -target:library or -target:module), any other output files produced in the same compilation must be modules (-target:module).

如果创建了一个程序集,则可以用 CLSCompliantAttribute 属性指示全部或部分代码是符合 CLS 的。If you create an assembly, you can indicate that all or part of your code is CLS compliant with the CLSCompliantAttribute attribute.

// target_clscompliant.cs  
[assembly:System.CLSCompliant(true)]   // specify assembly compliance  
[System.CLSCompliant(false)]   // specify compliance for an element  
public class TestClass  
    public static void Main() {}  

有关如何以编程方式设置此编译器选项的详细信息,请参阅 OutputTypeFor more information about setting this compiler option programmatically, see OutputType.

请参阅See also