/target (C# 編譯器選項)

/target 編譯器選項可以用下列四種格式中的任何一種指定:

除非您指定的是 /target:module,否則 /target 會將 .NET Framework 組件資訊清單置於輸出檔。 如需詳細資訊,請參閱 Common Language Runtime 中的組件常見屬性

如果您沒有指定 .exe 輸出檔,組件資訊清單會置於編譯中的第一個 .exe 輸出檔或第一個 DLL。 例如,下列命令列會將資訊清單檔置於 1.exe:

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

編譯器每次編譯只建立一個組件資訊清單。 編譯的所有檔案資訊都放置在組件資訊清單中。 除了以 /target:module 所建立的輸出檔之外,所有的輸出檔都可以包含一個組件資訊清單。 當命令列上產生多個輸出檔時,此時只能建立一個組件,而且這個組件必須進入該命令列指定的第一個輸出檔。 不論第一個輸出檔為何 (/target:exe/target:winexe/target:library/target:module),相同編譯中產生的任何其他輸出檔都必須是模組 (/target:module)。

如果您建立了組件,便可使用 CLSCompliantAttribute 屬性將所有或部分程式碼指定為符合 CLS。

// 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() {}
}

如需以程式設計方式設定這個編譯器選項的詳細資訊,請參閱 OutputType

請參閱

其他資源

C# 編譯器選項

專案屬性 (Visual Studio)