-deterministic-deterministic

可讓編譯器產生相同輸入之編譯間的逐一位元組輸出相同的組件。Causes the compiler to produce an assembly whose byte-for-byte output is identical across compilations for identical inputs.

語法Syntax

-deterministic

備註Remarks

根據預設,一組指定輸入的編譯器輸出是唯一的,因為編譯器會新增時間戳記以及透過亂數所產生的 GUID。By default, compiler output from a given set of inputs is unique, since the compiler adds a timestamp and a GUID that is generated from random numbers. 您可以使用 -deterministic 選項來產生「確定性組件」**,這是只要輸入維持不變,其二進位內容在編譯之間就相同的組件。You use the -deterministic option to produce a deterministic assembly, one whose binary content is identical across compilations as long as the input remains the same.

編譯器會基於確定性而考慮下列輸入:The compiler considers the following inputs for the purpose of determinism:

  • 命令列參數序列。The sequence of command-line parameters.
  • 編譯器之 .rsp 回應檔的內容。The contents of the compiler's .rsp response file.
  • 使用的編譯器精確版本和其參考的組件。The precise version of the compiler used, and its referenced assemblies.
  • 目前的目錄路徑。The current directory path.
  • 以直接或間接方式明確地傳遞給編譯器之所有檔案的二進位內容,包含:The binary contents of all files explicitly passed to the compiler either directly or indirectly, including:
    • 原始程式檔Source files
    • 參考的組件Referenced assemblies
    • 參考的模組Referenced modules
    • 資源Resources
    • 強式名稱金鑰檔The strong name key file
    • @ 回應檔@ response files
    • 分析器Analyzers
    • 規則集Rulesets
    • 分析器可能使用的其他檔案Additional files that may be used by analyzers
  • 目前文化特性 (Culture) (適用於用來產生診斷和例外狀況訊息的語言)。The current culture (for the language in which diagnostics and exception messages are produced).
  • 如果未指定編碼,則為預設編碼 (或目前字碼頁)。The default encoding (or the current code page) if the encoding is not specified.
  • 存在、不存在,以及編譯器搜尋路徑 (例如,透過 -lib-recurse 指定) 上檔案的內容。The existence, non-existence, and contents of files on the compiler's search paths (specified, for example, by -lib or -recurse).
  • 在其上執行編譯器的 CLR 平台。The CLR platform on which the compiler is run.
  • %LIBPATH% 的值,可能會影響分析器相依性載入。The value of %LIBPATH%, which can affect analyzer dependency loading.

來源公開可用時,確定性編譯可以用於建立是否從信任的來源編譯二進位檔。When sources are publicly available, deterministic compilation can be used for establishing whether a binary is compiled from a trusted source. 它也可以用於持續建置系統,確定是否需要執行與二進位檔變更相依的建置步驟。It can also be useful in a continuous build system for determining whether build steps that are dependent on changes to a binary need to be executed.

另請參閱See also