依分類列出的 C# 編譯器選項C# Compiler Options Listed by Category

下列編譯器選項會依類別排序。The following compiler options are sorted by category. 如需依字母順序排列的清單,請參閱依字母順序列出的 C# 編譯器選項For an alphabetical list, see C# Compiler Options Listed Alphabetically.

最佳化Optimization

選項Option 用途Purpose
-filealign-filealign 指定輸出檔案中區段的大小。Specifies the size of sections in the output file.
-optimize-optimize 啟用/停用最佳化。Enables/disables optimizations.

輸出檔Output Files

選項Option 用途Purpose
-deterministic-deterministic 可讓編譯器輸出在輸入相同時編譯之間二進位內容相同的組件。Causes the compiler to output an assembly whose binary content is identical across compilations if inputs are identical.
-doc-doc 指定要寫入已處理文件註解的 XML 檔案。Specifies an XML file where processed documentation comments are to be written.
-out-out 指定輸出檔。Specifies the output file.
-pathmap-pathmap 指定編譯器所輸出來源路徑名稱的對應。Specify a mapping for source path names output by the compiler
-pdb-pdb 指定 .pdb 檔案的檔案名稱和位置。Specifies the file name and location of the .pdb file.
-platform-platform 指定輸出平台。Specify the output platform.
-preferreduilang-preferreduilang 指定編譯器輸出的語言。Specify a language for compiler output.
-refout-refout 除了主要組件,再另外產生參考組件。Generate a reference assembly in addition to the primary assembly.
-refonly-refonly 產生參考組件,而非主要組件。Generate a reference assembly instead of a primary assembly.
-target-target 使用下列五個選項之一來指定輸出檔案的格式:-target:appcontainerexe-target:exe-target:library-target:module-target:winexe-target:winmdobjSpecifies the format of the output file using one of five options: -target:appcontainerexe, -target:exe, -target:library, -target:module, -target:winexe, or -target:winmdobj.
-modulename:<字串>-modulename:<string> 指定來源模組的名稱Specify the name of the source module

.NET Framework 組件.NET Framework Assemblies

選項Option 用途Purpose
-addmodule-addmodule 指定要成為此組件一部分的一或多個模組。Specifies one or more modules to be part of this assembly.
-delaysign-delaysign 指示編譯器新增公開金鑰,但是讓組件不帶正負號。Instructs the compiler to add the public key but to leave the assembly unsigned.
-keycontainer-keycontainer 指定密碼編譯金鑰容器的名稱。Specifies the name of the cryptographic key container.
-keyfile-keyfile 指定包含密碼編譯金鑰的檔名。Specifies the filename containing the cryptographic key.
-lib-lib 指定透過 -reference 參考的組件位置。Specifies the location of assemblies referenced by means of -reference.
-nostdlib-nostdlib 指示編譯器不要匯入標準程式庫 (mscorlib.dll)。Instructs the compiler not to import the standard library (mscorlib.dll).
-publicsign-publicsign 套用公開金鑰而不簽署組件,但會在組件中設定此位元以表示該組件已經過簽署。Apply a public key without signing the assembly, but set the bit in the assembly indicating the assembly is signed.
-reference-reference 從包含組件的檔案匯入中繼資料。Imports metadata from a file that contains an assembly.
-analyzer-analyzer 從這個組件執行分析器 (簡短形式:/a)Run the analyzers from this assembly (Short form: /a)
-additionalfile-additionalfile 命名不會直接影響程式碼產生,但可能被分析器用來產生錯誤或警告的其他檔案。Names additional files that don't directly affect code generation but may be used by analyzers for producing errors or warnings.
-embed-embed 在 PDB 中內嵌所有來源檔案。Embed all source files in the PDB.
-embed:<檔案清單>-embed:<file list> 在 PDB 中內嵌特定檔案。Embed specific files in the PDB.

偵錯/錯誤檢查Debugging/Error Checking

選項Option 用途Purpose
-bugreport-bugreport 建立檔案,其中包含可簡化錯誤回報的資訊。Creates a file that contains information that makes it easy to report a bug.
-checked-checked 指定超出資料類型範圍的整數算術,是否會導致在執行階段發生例外狀況。Specifies whether integer arithmetic that overflows the bounds of the data type will cause an exception at run time.
-debug-debug 指示編譯器發出偵錯資訊。Instruct the compiler to emit debugging information.
-errorreport-errorreport 設定錯誤報告行為。Sets error reporting behavior.
-fullpaths-fullpaths 在編譯器輸出中指定檔案的絕對路徑。Specifies the absolute path to the file in compiler output.
-nowarn-nowarn 抑制編譯器產生指定的警告。Suppresses the compiler's generation of specified warnings.
-warn-warn 設定警告層級。Sets the warning level.
-warnaserror-warnaserror 將警告提升為錯誤。Promotes warnings to errors.
-ruleset:<檔案>-ruleset:<file> 指定停用特定診斷的規則集檔案。Specify a ruleset file that disables specific diagnostics.

前置處理器Preprocessor

選項Option 用途Purpose
-define-define 定義前置處理器符號。Defines preprocessor symbols.

資源Resources

選項Option 用途Purpose
-link-link 將指定組件中的 COM 類型資訊提供給專案使用。Makes COM type information in specified assemblies available to the project.
-linkresource-linkresource 建立與 Managed 資源的連結。Creates a link to a managed resource.
-resource-resource 將 .NET Framework 資源內嵌到輸出檔中。Embeds a .NET Framework resource into the output file.
-win32icon-win32icon 指定要插入輸出檔中的 .ico 檔案。Specifies an .ico file to insert into the output file.
-win32res-win32res 指定要插入輸出檔中的 Win32 資源。Specifies a Win32 resource to insert into the output file.

其他Miscellaneous

選項Option 用途Purpose
@ 指定回應檔。Specifies a response file.
-?-? 將編譯器選項列出至 stdout。Lists compiler options to stdout.
.-baseaddress-baseaddress 指定載入 DLL 時慣用的基底位址。Specifies the preferred base address at which to load a DLL.
-codepage-codepage 指定編譯過程中所有原始程式碼檔使用的字碼頁。Specifies the code page to use for all source code files in the compilation.
-help-help 將編譯器選項列出至 stdout。Lists compiler options to stdout.
-highentropyva-highentropyva 指定可執行檔支援位址空間配置隨機載入 (ASLR)。Specifies that the executable file supports address space layout randomization (ASLR).
-langversion-langversion 指定語言版本:預設、ISO-1、ISO-2、3、4、5、6、7、7.1、7.2、7.3 或最新Specify language version: Default, ISO-1, ISO-2, 3, 4, 5, 6, 7, 7.1, 7.2, 7.3, or Latest
-main-main 指定 Main 方法的位置。Specifies the location of the Main method.
-noconfig-noconfig 指示編譯器不要使用 csc.rsp 進行編譯。Instructs the compiler not to compile with csc.rsp.
-nologo-nologo 隱藏編譯器橫幅資訊。Suppresses compiler banner information.
-recurse-recurse 搜尋要編譯之原始程式檔的子目錄。Searches subdirectories for source files to compile.
-subsystemversion-subsystemversion 指定可執行檔能夠使用的最低子系統版本。Specifies the minimum version of the subsystem that the executable file can use.
-unsafe-unsafe 啟用使用 unsafe 關鍵字的程式碼編譯。Enables compilation of code that uses the unsafe keyword.
-utf8output-utf8output 使用 UTF-8 編碼顯示編譯器輸出。Displays compiler output using UTF-8 encoding.
-parallel[+|-]-parallel[+|-] 指定是否要使用並行組建 (+)。Specifies whether to use concurrent build (+).
-checksumalgorithm:<alg>-checksumalgorithm:<alg> 指定用於計算儲存在 PDB 的來源檔案總和檢查碼的演算法。Specify the algorithm for calculating the source file checksum stored in PDB. 支援的值為:SHA1 (預設) 或 SHA256。Supported values are: SHA1 (default) or SHA256.
由於 SHA1 的衝突問題,Microsoft 建議使用 SHA256。Due to collision problems with SHA1, Microsoft recommends SHA256.

過時的選項Obsolete Options

選項Option 用途Purpose
-incremental-incremental 啟用累加編譯。Enables incremental compilation.

另請參閱See also