NuGet CLI 環境變數NuGet CLI environment variables

您可以透過數個環境變數來設定 nuget.exe CLI 的行為, 這會影響整部電腦、使用者或進程層級上的 nuget.exe。The behavior of the nuget.exe CLI can be configured through a number of environment variables, which affect nuget.exe on computer-wide, user, or process levels. 環境變數一律會覆寫檔案NuGet.Config中的任何設定, 讓組建伺服器能夠變更適當的設定, 而不需要修改任何檔案。Environment variables always override any settings in NuGet.Config files, allowing build servers to change appropriate settings without modifying any files.

一般而言, 直接在命令列或 NuGet 設定檔中指定的選項具有優先順序, 但有一些例外狀況, 例如FORCE_NUGET_EXE_INTERACTIVEIn general, options specified directly on the command line or in NuGet configuration files have precedence, but there are a few exceptions such as FORCE_NUGET_EXE_INTERACTIVE. 如果您發現 nuget.exe 在不同電腦之間的行為不同, 環境變數可能是原因。If you find that nuget.exe behaves differently between different computers, an environment variable could be the cause. 例如, Azure Web Apps Kudu (在部署期間使用) 已將NUGET_XMLDOC_MODE設定為 [略過], 以加速封裝還原效能並節省磁碟空間。For example, Azure Web Apps Kudu (used during deployment) has NUGET_XMLDOC_MODE set to skip to speed up package restore performance and save disk space.

NuGet CLI 會使用 MSBuild 來讀取專案檔案。The NuGet CLI uses MSBuild to read the project files. 在 MSBuild 評估期間, 所有環境變數都可做為屬性All environment variables are available as properties during the MSBuild evaluation. NuGet 套件和還原為 MSBuild 目標中記載的屬性清單, 也可以設定為環境變數。The list of properties documented in NuGet pack and restore as MSBuild targets can also be set as environment variables.

變數Variable 描述Description 備註Remarks
http_proxyhttp_proxy 用於 NuGet HTTP 作業的 HTTP proxy。Http proxy used for NuGet HTTP operations. 這會指定為http://<username>:<password>@proxy.comThis would be specified as http://<username>:<password>
no_proxyno_proxy 設定網域以略過使用 proxy。Configures domains to bypass from using proxy. 指定為以逗號 (,) 分隔的網域。Specified as domains separated by comma (,).
EnableNuGetPackageRestoreEnableNuGetPackageRestore 如果在還原時封裝需要時, NuGet 應隱含授與同意, 則為的旗標。Flag for if NuGet should implicitly grant consent if that's required by package on restore. 指定的旗標會被視為true1, 任何其他值會被視為未設定旗標。Specified flag is treated as true or 1, any other value treated as flag not set.
NUGET_EXE_NO_PROMPTNUGET_EXE_NO_PROMPT 防止 exe 提示輸入認證。Prevents the exe for prompting for credentials. 除了 null 或空字串以外的任何值都會被視為設定此旗標/true。Any value except null or empty string will be treated as this flag set/true.
FORCE_NUGET_EXE_INTERACTIVEFORCE_NUGET_EXE_INTERACTIVE 用來強制互動模式的全域環境變數。Global environment variable to force interactive mode. 除了 null 或空字串以外的任何值都會被視為設定此旗標/true。Any value except null or empty string will be treated as this flag set/true.
NUGET_PACKAGESNUGET_PACKAGES 要用於全域封裝資料夾的路徑, 如管理全域套件和快取資料夾中所述。Path to use for the global-packages folder as described on Managing the global packages and cache folders. 指定為絕對路徑。Specified as absolute path.
NUGET_FALLBACK_PACKAGESNUGET_FALLBACK_PACKAGES 全域回溯封裝資料夾。Global fallback packages folders. 以分號分隔的絕對資料夾路徑 (;)。Absolute folder paths separated by semicolon (;).
NUGET_HTTP_CACHE_PATHNUGET_HTTP_CACHE_PATH 要用於HTTP快取資料夾的路徑, 如管理全域套件和快取資料夾中所述。Path to use for the http-cache folder as described on Managing the global packages and cache folders. 指定為絕對路徑。Specified as absolute path.
NUGET_PERSIST_DGNUGET_PERSIST_DG 表示是否應該保存 dg 檔案 (從 MSBuild 收集的資料) 的旗標。Flag indicating if dg files (data collected from MSBuild) should be persisted. 指定為truefalse (預設值), 如果未設定 NUGET_PERSIST_DG_PATH, 將會儲存至臨時目錄 (在目前環境臨時目錄中的 NuGetScratch 資料夾)。Specified as true or false (default), if NUGET_PERSIST_DG_PATH not set will be stored to temporary directory (NuGetScratch folder in current environment temp directory).
NUGET_PERSIST_DG_PATHNUGET_PERSIST_DG_PATH 保存 dg 檔案的路徑。Path to persist dg files. 指定為絕對路徑, 只有在NUGET_PERSIST_DG設定為 true 時, 才會使用此選項。Specified as absolute path, this option is only used when NUGET_PERSIST_DG is set to true.
NUGET_RESTORE_MSBUILD_ARGSNUGET_RESTORE_MSBUILD_ARGS 設定其他 MSBuild 引數。Sets additional MSBuild arguments. 傳遞引數與傳遞給 msbuild.exe 的方式相同。Pass arguments identical to how you would pass them to msbuild.exe. 將專案屬性 Foo 從命令列設定為值列的範例是/p: Foo = BarAn example of setting a project property Foo from the command line to value Bar would be /p:Foo=Bar
NUGET_RESTORE_MSBUILD_VERBOSITYNUGET_RESTORE_MSBUILD_VERBOSITY 設定 MSBuild 記錄詳細資訊。Sets the MSBuild log verbosity. 預設值為quiet ("/v: q")。Default is quiet ("/v:q"). 可能的值q [uiet]m [inimal]n [ormal]d [etailed][診斷] [nostic]Possible values q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
NUGET_SHOW_STACKNUGET_SHOW_STACK 決定是否應該對使用者顯示完整的例外狀況 (包括堆疊追蹤)。Determines whether the full exception (including stack trace) should be displayed to the user. 指定為truefalse (預設值)。Specified as true or false (default).
NUGET_XMLDOC_MODENUGET_XMLDOC_MODE 決定如何處理元件 XML 檔檔案的解壓縮。Determines how assemblies XML documentation file extraction should be handled. 支援的模式為skip (不要解壓縮 XML 檔檔)、壓縮(將 xml 檔檔案儲存為 zip 封存) 或none (預設值, 將 xml 檔檔案視為一般檔案)。Supported modes are skip (do not extract XML documentation files), compress (store XML doc files as a zip archive) or none (default, treat XML doc files as regular files).
NUGET_CERT_REVOCATION_MODENUGET_CERT_REVOCATION_MODE 決定在安裝或還原已簽署的套件時, 是否要檢查用來簽署封裝之憑證的撤銷狀態。Determines how the revocation status check of the certificate used to sign a package, is performed when a signed package is installed or restored. [未設定] 時, online預設為。When not set, defaults to online. 可能值上線(預設值),離線Possible values online (default), offline. NU3028相關Related to NU3028