共用方式為


NuGetCommand@2 - NuGet v2 工作

使用此工作來還原、封裝或推送 NuGet 套件,或執行 NuGet 命令。 此工作支援 NuGet.org 和已驗證的摘要,例如 Azure Artifacts 和 MyGet。 此工作也會使用 NuGet.exe,並與 .NET Framework 應用程式搭配使用。 針對 .NET Core 和 .NET Standard 應用程式,請使用 .NET Core 工作。

語法

# NuGet v2
# Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
- task: NuGetCommand@2
  inputs:
    command: 'restore' # 'restore' | 'pack' | 'push' | 'custom'. Required. Command. Default: restore.
    restoreSolution: '**/*.sln' # string. Alias: solution. Required when command = restore. Path to solution, packages.config, or project.json. Default: **/*.sln.
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' # string. Alias: searchPatternPush. Required when command = push. Path to NuGet package(s) to publish. Default: $(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg.
    #nuGetFeedType: 'internal' # 'internal' | 'external'. Required when command = push. Target feed location. Default: internal.
    #publishVstsFeed: # string. Alias: feedPublish. Required when command = push && nuGetFeedType = internal. Target feed. 
    #allowPackageConflicts: false # boolean. Optional. Use when command = push && nuGetFeedType = internal. Allow duplicates to be skipped. Default: false.
    #publishFeedCredentials: # string. Alias: externalEndpoint. Required when command = push && nuGetFeedType = external. NuGet server. 
    #packagesToPack: '**/*.csproj' # string. Alias: searchPatternPack. Required when command = pack. Path to csproj or nuspec file(s) to pack. Default: **/*.csproj.
    #configuration: '$(BuildConfiguration)' # string. Alias: configurationToPack. Optional. Use when command = pack. Configuration to package. Default: $(BuildConfiguration).
    #packDestination: '$(Build.ArtifactStagingDirectory)' # string. Alias: outputDir. Optional. Use when command = pack. Package folder. Default: $(Build.ArtifactStagingDirectory).
    #arguments: # string. Required when command = custom. Command and arguments. 
  # Feeds and authentication
    feedsToUse: 'select' # 'select' | 'config'. Alias: selectOrConfig. Required when command = restore. Feeds to use. Default: select.
    #vstsFeed: # string. Alias: feedRestore. Optional. Use when selectOrConfig = select && command = restore. Use packages from this Azure Artifacts/TFS feed. Select from the dropdown or enter [project name/]feed name. 
    #includeNuGetOrg: true # boolean. Optional. Use when selectOrConfig = select && command = restore. Use packages from NuGet.org. Default: true.
    #nugetConfigPath: # string. Optional. Use when selectOrConfig = config && command = restore. Path to NuGet.config. 
    #externalFeedCredentials: # string. Alias: externalEndpoints. Optional. Use when selectOrConfig = config && command = restore. Credentials for feeds outside this organization/collection. 
  # Advanced
    #noCache: false # boolean. Optional. Use when command = restore. Disable local cache. Default: false.
    #disableParallelProcessing: false # boolean. Optional. Use when command = restore. Disable parallel processing. Default: false.
    #restoreDirectory: # string. Alias: packagesDirectory. Optional. Use when command = restore. Destination directory. 
    #verbosityRestore: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = restore. Verbosity. Default: Detailed.
  # Advanced
    #publishPackageMetadata: true # boolean. Optional. Use when command = push && nuGetFeedType = internal. Publish pipeline metadata. Default: true.
    #verbosityPush: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = push. Verbosity. Default: Detailed.
  # Pack options
    #versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required when command = pack. Automatic package versioning. Default: off.
    #includeReferencedProjects: false # boolean. Optional. Use when versioningScheme = off && command = pack. Include referenced projects. Default: false.
    #versionEnvVar: # string. Required when versioningScheme = byEnvVar && command = pack. Environment variable. 
    #majorVersion: '1' # string. Alias: requestedMajorVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Major. Default: 1.
    #minorVersion: '0' # string. Alias: requestedMinorVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Minor. Default: 0.
    #patchVersion: '0' # string. Alias: requestedPatchVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Patch. Default: 0.
    #packTimezone: 'utc' # 'utc' | 'local'. Optional. Use when versioningScheme = byPrereleaseNumber && command = pack. Time zone. Default: utc.
    #includeSymbols: false # boolean. Optional. Use when command = pack. Create symbols package. Default: false.
    #toolPackage: false # boolean. Optional. Use when command = pack. Tool Package. Default: false.
  # Advanced
    #buildProperties: # string. Optional. Use when command = pack. Additional build properties. 
    #basePath: # string. Optional. Use when command = pack. Base path. 
    #verbosityPack: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = pack. Verbosity. Default: Detailed.
# NuGet v2
# Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
- task: NuGetCommand@2
  inputs:
    command: 'restore' # 'restore' | 'pack' | 'push' | 'custom'. Required. Command. Default: restore.
    restoreSolution: '**/*.sln' # string. Alias: solution. Required when command = restore. Path to solution, packages.config, or project.json. Default: **/*.sln.
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' # string. Alias: searchPatternPush. Required when command = push. Path to NuGet package(s) to publish. Default: $(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg.
    #nuGetFeedType: 'internal' # 'internal' | 'external'. Required when command = push. Target feed location. Default: internal.
    #publishVstsFeed: # string. Alias: feedPublish. Required when command = push && nuGetFeedType = internal. Target feed. 
    #allowPackageConflicts: false # boolean. Optional. Use when command = push && nuGetFeedType = internal. Allow duplicates to be skipped. Default: false.
    #publishFeedCredentials: # string. Alias: externalEndpoint. Required when command = push && nuGetFeedType = external. NuGet server. 
    #packagesToPack: '**/*.csproj' # string. Alias: searchPatternPack. Required when command = pack. Path to csproj or nuspec file(s) to pack. Default: **/*.csproj.
    #configuration: '$(BuildConfiguration)' # string. Alias: configurationToPack. Optional. Use when command = pack. Configuration to package. Default: $(BuildConfiguration).
    #packDestination: '$(Build.ArtifactStagingDirectory)' # string. Alias: outputDir. Optional. Use when command = pack. Package folder. Default: $(Build.ArtifactStagingDirectory).
    #arguments: # string. Required when command = custom. Command and arguments. 
  # Feeds and authentication
    feedsToUse: 'select' # 'select' | 'config'. Alias: selectOrConfig. Required when command = restore. Feeds to use. Default: select.
    #vstsFeed: # string. Alias: feedRestore. Optional. Use when selectOrConfig = select && command = restore. Use packages from this Azure Artifacts/TFS feed. 
    #includeNuGetOrg: true # boolean. Optional. Use when selectOrConfig = select && command = restore. Use packages from NuGet.org. Default: true.
    #nugetConfigPath: # string. Optional. Use when selectOrConfig = config && command = restore. Path to NuGet.config. 
    #externalFeedCredentials: # string. Alias: externalEndpoints. Optional. Use when selectOrConfig = config && command = restore. Credentials for feeds outside this organization/collection. 
  # Advanced
    #noCache: false # boolean. Optional. Use when command = restore. Disable local cache. Default: false.
    #disableParallelProcessing: false # boolean. Optional. Use when command = restore. Disable parallel processing. Default: false.
    #restoreDirectory: # string. Alias: packagesDirectory. Optional. Use when command = restore. Destination directory. 
    #verbosityRestore: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = restore. Verbosity. Default: Detailed.
  # Advanced
    #publishPackageMetadata: true # boolean. Optional. Use when command = push && nuGetFeedType = internal. Publish pipeline metadata. Default: true.
    #verbosityPush: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = push. Verbosity. Default: Detailed.
  # Pack options
    #versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required when command = pack. Automatic package versioning. Default: off.
    #includeReferencedProjects: false # boolean. Optional. Use when versioningScheme = off && command = pack. Include referenced projects. Default: false.
    #versionEnvVar: # string. Required when versioningScheme = byEnvVar && command = pack. Environment variable. 
    #majorVersion: '1' # string. Alias: requestedMajorVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Major. Default: 1.
    #minorVersion: '0' # string. Alias: requestedMinorVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Minor. Default: 0.
    #patchVersion: '0' # string. Alias: requestedPatchVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Patch. Default: 0.
    #packTimezone: 'utc' # 'utc' | 'local'. Optional. Use when versioningScheme = byPrereleaseNumber && command = pack. Time zone. Default: utc.
    #includeSymbols: false # boolean. Optional. Use when command = pack. Create symbols package. Default: false.
    #toolPackage: false # boolean. Optional. Use when command = pack. Tool Package. Default: false.
  # Advanced
    #buildProperties: # string. Optional. Use when command = pack. Additional build properties. 
    #basePath: # string. Optional. Use when command = pack. Base path. 
    #verbosityPack: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = pack. Verbosity. Default: Detailed.
# NuGet v2
# Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Package Management and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
- task: NuGetCommand@2
  inputs:
    command: 'restore' # 'restore' | 'pack' | 'push' | 'custom'. Required. Command. Default: restore.
    restoreSolution: '**/*.sln' # string. Alias: solution. Required when command = restore. Path to solution, packages.config, or project.json. Default: **/*.sln.
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' # string. Alias: searchPatternPush. Required when command = push. Path to NuGet package(s) to publish. Default: $(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg.
    #nuGetFeedType: 'internal' # 'internal' | 'external'. Required when command = push. Target feed location. Default: internal.
    #publishVstsFeed: # string. Alias: feedPublish. Required when command = push && nuGetFeedType = internal. Target feed. 
    #allowPackageConflicts: false # boolean. Optional. Use when command = push && nuGetFeedType = internal. Allow duplicates to be skipped. Default: false.
    #publishFeedCredentials: # string. Alias: externalEndpoint. Required when command = push && nuGetFeedType = external. NuGet server. 
    #packagesToPack: '**/*.csproj' # string. Alias: searchPatternPack. Required when command = pack. Path to csproj or nuspec file(s) to pack. Default: **/*.csproj.
    #configuration: '$(BuildConfiguration)' # string. Alias: configurationToPack. Optional. Use when command = pack. Configuration to package. Default: $(BuildConfiguration).
    #packDestination: '$(Build.ArtifactStagingDirectory)' # string. Alias: outputDir. Optional. Use when command = pack. Package folder. Default: $(Build.ArtifactStagingDirectory).
    #arguments: # string. Required when command = custom. Command and arguments. 
  # Feeds and authentication
    feedsToUse: 'select' # 'select' | 'config'. Alias: selectOrConfig. Required when command = restore. Feeds to use. Default: select.
    #vstsFeed: # string. Alias: feedRestore. Optional. Use when selectOrConfig = select && command = restore. Use packages from this Azure Artifacts/TFS feed. 
    #includeNuGetOrg: true # boolean. Optional. Use when selectOrConfig = select && command = restore. Use packages from NuGet.org. Default: true.
    #nugetConfigPath: # string. Optional. Use when selectOrConfig = config && command = restore. Path to NuGet.config. 
    #externalFeedCredentials: # string. Alias: externalEndpoints. Optional. Use when selectOrConfig = config && command = restore. Credentials for feeds outside this account/collection. 
  # Advanced
    #noCache: false # boolean. Optional. Use when command = restore. Disable local cache. Default: false.
    #disableParallelProcessing: false # boolean. Optional. Use when command = restore. Disable parallel processing. Default: false.
    #restoreDirectory: # string. Alias: packagesDirectory. Optional. Use when command = restore. Destination directory. 
    #verbosityRestore: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = restore. Verbosity. Default: Detailed.
  # Advanced
    #verbosityPush: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = push. Verbosity. Default: Detailed.
  # Pack options
    #versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required when command = pack. Automatic package versioning. Default: off.
    #includeReferencedProjects: false # boolean. Optional. Use when versioningScheme = off && command = pack. Include referenced projects. Default: false.
    #versionEnvVar: # string. Required when versioningScheme = byEnvVar && command = pack. Environment variable. 
    #majorVersion: '1' # string. Alias: requestedMajorVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Major. Default: 1.
    #minorVersion: '0' # string. Alias: requestedMinorVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Minor. Default: 0.
    #patchVersion: '0' # string. Alias: requestedPatchVersion. Required when versioningScheme = byPrereleaseNumber && command = pack. Patch. Default: 0.
    #packTimezone: 'utc' # 'utc' | 'local'. Optional. Use when versioningScheme = byPrereleaseNumber && command = pack. Time zone. Default: utc.
    #includeSymbols: false # boolean. Optional. Use when command = pack. Create symbols package. Default: false.
    #toolPackage: false # boolean. Optional. Use when command = pack. Tool Package. Default: false.
  # Advanced
    #buildProperties: # string. Optional. Use when command = pack. Additional build properties. 
    #basePath: # string. Optional. Use when command = pack. Base path. 
    #verbosityPack: 'Detailed' # 'Quiet' | 'Normal' | 'Detailed'. Optional. Use when command = pack. Verbosity. Default: Detailed.

輸入

command - 命令
string。 必填。 允許的值:restorepackpushcustom。 預設值:restore

指定要執行的 NuGet 命令。 使用 custom 值來新增自變數或使用不同的命令。


restoreSolution - 解決方案路徑、packages.config或 project.json
輸入別名:solutionstringcommand = restore時為必要項。 預設值:**/*.sln

指定參考要還原之封裝的方案路徑、packages.configproject.json 檔案。


使用feedsToUse - 摘要
輸入別名:selectOrConfigstringcommand = restore時為必要項。 允許的值:select(摘要)我在這裡選取),config(我的 NuGet.config中的摘要)。 預設值:select

指定 Azure Artifacts 和/或 NuGet.org 的摘要,讓工作與 select 值搭配使用。 或者,您可以將 NuGet.config 檔案認可至原始程式碼存放庫,並使用 config 值將其路徑設定為值。


vstsFeed - 使用此 Azure Artifacts/TFS 摘要中的套件。從下拉式清單中選取 ,或輸入 [項目名稱/]摘要名稱。
輸入別名:feedRestorestring。 自選。 selectOrConfig = select && command = restore時使用 。

在產生的 NuGet.config中指定選取的摘要。 您必須安裝套件管理並獲授權,才能在這裡指定摘要。


vstsFeed - 使用此 Azure Artifacts/TFS 摘要中的套件
輸入別名:feedRestorestring。 自選。 selectOrConfig = select && command = restore時使用 。

在產生的 NuGet.config中指定選取的摘要。 您必須安裝套件管理並獲授權,才能在這裡指定摘要。


includeNuGetOrg - 使用來自 NuGet.org的套件
boolean。 自選。 selectOrConfig = select && command = restore時使用 。 預設值:true

在產生的 NuGet.config中包含 NuGet.org。


nugetConfigPath - NuGet.config 的路徑
string。 自選。 selectOrConfig = config && command = restore時使用 。

指定存放庫中 NuGet.config 的路徑,以決定要從中還原封裝的摘要。


externalFeedCredentials - 此組織/集合外部摘要的認證
輸入別名:externalEndpointsstring。 自選。 selectOrConfig = config && command = restore時使用 。

指定要用於位於所選 NuGet.config之外部登錄的認證。 這是 NuGet 服務連線的名稱。 針對此組織或集合中的摘要,請將此保留空白;會自動使用組建的認證。


externalFeedCredentials - 此帳戶/集合外部摘要的認證
輸入別名:externalEndpointsstring。 自選。 selectOrConfig = config && command = restore時使用 。

指定要用於位於所選 NuGet.config之外部登錄的認證。 這是 NuGet 服務連線的名稱。 針對此帳戶或集合中的摘要,請將此保留空白;會自動使用組建的認證。


noCache - 停用本機快取
boolean。 自選。 command = restore時使用 。 預設值:false

當設定為 true時,防止 NuGet 使用本機電腦快取中的套件。


disableParallelProcessing - 停用平行處理
boolean。 自選。 command = restore時使用 。 預設值:false

當設定為 true時,防止 NuGet 在平行進程中安裝多個套件。


restoreDirectory - 目的地目錄
輸入別名:packagesDirectorystring。 自選。 command = restore時使用 。

指定安裝套件的資料夾。 如果未指定資料夾,封裝會還原至 packages/ 資料夾,以及選取的解決方案、packages.configproject.json


verbosityRestore - 詳細資訊
string。 自選。 command = restore時使用 。 允許的值:QuietNormalDetailed。 預設值:Detailed

指定輸出中顯示的詳細數據量。


packagesToPush - 發佈 的 NuGet 套件路徑
輸入別名:searchPatternPushstringcommand = push時為必要項。 預設值:$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg

指定要比對的模式,或要上傳 nupkg 檔案的路徑。 多個模式可以以分號分隔。


nuGetFeedType - 目標摘要位置
stringcommand = push時為必要項。 允許的值:internal(此組織/集合)、external(外部 NuGet 伺服器(包括其他帳戶/集合)。 預設值:internal

指定目標摘要是內部摘要/集合或外部 NuGet 伺服器。


nuGetFeedType - 目標摘要位置
stringcommand = push時為必要項。 允許的值:internal(此帳戶/集合)、external(外部 NuGet 伺服器(包括其他帳戶/集合)。 預設值:internal

指定目標摘要是內部摘要/集合或外部 NuGet 伺服器。


publishVstsFeed - 目標摘要
輸入別名:feedPublishstringcommand = push && nuGetFeedType = internal時為必要項。

指定裝載在此帳戶中的摘要。 您必須安裝 Azure Artifacts 並獲授權,才能在這裡選取摘要。


publishPackageMetadata - 發佈管線元數據
boolean。 自選。 command = push && nuGetFeedType = internal時使用 。 預設值:true

變更一組持續發行套件內已變更套件子集的版本號碼。


allowPackageConflicts - 允許略過重複專案
boolean。 自選。 command = push && nuGetFeedType = internal時使用 。 預設值:false

即使某些套件遭到拒絕且發生 409 衝突錯誤,仍會報告工作成功。

此選項目前僅適用於 Azure Pipelines 和 Windows 代理程式。 如果 NuGet.exe 發生衝突,工作將會失敗。 如果您位於 Proxy 環境中,此選項將無法運作,而且發佈將會失敗。


publishFeedCredentials - NuGet 伺服器
輸入別名:externalEndpointstringcommand = push && nuGetFeedType = external時為必要項。

指定包含外部 NuGet 伺服器認證的 NuGet 服務連線。


verbosityPush - 詳細資訊
string。 自選。 command = push時使用 。 允許的值:QuietNormalDetailed。 預設值:Detailed

指定輸出中顯示的詳細數據量。


packagesToPack - csproj 或 nuspec 檔案的路徑以封裝
輸入別名:searchPatternPackstringcommand = pack時為必要項。 預設值:**/*.csproj

指定工作用來搜尋要封裝之 csproj 目錄的模式。

您可以使用分號分隔多個模式,並以 !做為負數。 範例:**\*.csproj;!**\*.Tests.csproj


configuration - 組態封裝
輸入別名:configurationToPackstring。 自選。 command = pack時使用 。 預設值:$(BuildConfiguration)

指定使用 csproj 檔案時要封裝的組態。


packDestination - 套件資料夾
輸入別名:outputDirstring。 自選。 command = pack時使用 。 預設值:$(Build.ArtifactStagingDirectory)

指定工作建立封裝的資料夾。 如果值是空的,工作會在來源根目錄建立套件。


versioningScheme - 自動套件版本設定
stringcommand = pack時為必要項。 允許的值:offbyPrereleaseNumber(使用日期和時間)、byEnvVar(使用環境變數)、byBuildNumber(使用組建編號)。 預設值:off

根據指定的值套用自動套件版本設定。 此字串無法與 includeReferencedProjects搭配使用。 允許的值為:

  • byPrereleaseNumber - 使用日期和時間:工作會產生格式化為 X.Y.Z-ci-datetime相容版本,您可以在其中指定 X、Y 和 Z 的值。
  • byEnvVar - 使用環境變數:工作會使用您指定的環境變數,並包含您想要使用的版本號碼。
  • byBuildNumber - 使用組建編號:工作會使用組建編號來建立套件的版本。

注意

在 [一般] 下,將組建格式設定為 $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)


includeReferencedProjects - 包含參考的專案
boolean。 自選。 versioningScheme = off && command = pack時使用 。 預設值:false

包含參考的專案為相依性或封裝的一部分。 無法搭配自動套件版本設定使用。 如果參考的專案具有與專案同名的對應 nuspec 檔案,則會將參考的專案新增為相依性。 否則,參考的專案會新增為封裝的一部分。 深入瞭解 如何使用 NuGet CLI 的 pack 命令建立 NuGet 套件


versionEnvVar - 環境變數
stringversioningScheme = byEnvVar && command = pack時為必要項。

指定變數名稱,而不 $$env%


majorVersion - 主要
輸入別名:requestedMajorVersionstringversioningScheme = byPrereleaseNumber && command = pack時為必要項。 預設值:1

X版中的


minorVersion - 次要
輸入別名:requestedMinorVersionstringversioningScheme = byPrereleaseNumber && command = pack時為必要項。 預設值:0

Y版中的


patchVersion - Patch
輸入別名:requestedPatchVersionstringversioningScheme = byPrereleaseNumber && command = pack時為必要項。 預設值:0

Z版中的


packTimezone - 時區
string。 自選。 versioningScheme = byPrereleaseNumber && command = pack時使用 。 允許的值:utclocal(代理程式當地時間)。 預設值:utc

指定用來產生封裝版本所需的時區。 如果您使用裝載的組建代理程序,建議您選取 utc,因為其日期和時間可能會有所不同。


includeSymbols - 建立符號套件
boolean。 自選。 command = pack時使用 。 預設值:false

指定封裝包含來源和符號。 與 .nuspec 檔案搭配使用時,這會建立一般 NuGet 套件檔案和對應的符號套件。


toolPackage - 工具套件
boolean。 自選。 command = pack時使用 。 預設值:false

判斷項目的輸出檔是否應該位於工具資料夾中。


buildProperties - 其他組建屬性
string。 自選。 command = pack時使用 。

指定以分號分隔的 token=value 配對清單,其中 $token$ 檔案中出現的每個 .nuspec 都會取代為指定的值。 值可以是引號中的字串。


basePath - 基底路徑
string。 自選。 command = pack時使用 。

指定 nuspec 檔案中定義的檔案基底路徑。


verbosityPack - 詳細資訊
string。 自選。 command = pack時使用 。 允許的值:QuietNormalDetailed。 預設值:Detailed

指定輸出中顯示的詳細數據量。


arguments - 命令和自變數
stringcommand = custom時為必要項。

指定將傳遞至 NuGet.exe 執行的命令和自變數。 如果使用 NuGet 3.5 或更新版本,則會針對此組織或集合中專案集合建置服務有權存取的任何摘要,listrestorepublish 等已驗證的命令。


工作控制選項

除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制項選項和一般工作屬性

輸出變數

沒有。

言論

重要

NuGet 驗證 工作是向 Azure Artifacts 和其他 NuGet 存放庫進行驗證的新建議方式。 此工作不再採用新功能,而且只會解決重大錯誤。

使用此工作來安裝和更新 NuGet 套件相依性,或封裝併發佈 NuGet 套件。 使用 NuGet.exe 並使用 .NET Framework 應用程式。 針對 .NET Core 和 .NET Standard 應用程式,請使用 .NET Core 工作。

如果您的程式代碼相依於 NuGet 套件,請務必在 visual Studio 建置工作 之前新增此步驟。 此外,請務必清除該工作中已淘汰 還原 NuGet 套件 複選框。

如果您使用 .NET Core 或 .NET Standard,請使用 .NET Core 工作,此工作具有所有套件案例的完整支援,且目前由 dotnet 支援。

提示

此版本的 NuGet 工作預設會使用 NuGet 4.1.0。 若要選取不同版本的 NuGet,請使用 Tool Installer

版本控制配置

針對 byPrereleaseNumber ,版本會設定為您針對主要版本、次要版本和修補程式選擇的值,加上日期和時間,格式為 yyyymmdd-hhmmss

若為 byEnvVar ,版本會設定為環境變數的值,而環境變數的名稱是由 versionEnvVar 參數所指定,例如 MyVersion(沒有 $,只是環境變數名稱)。 請確定環境變數已設定為適當的 SemVer,例如 1.2.31.2.3-beta1

針對 byBuildNumber ,版本將會使用管線執行的組建編號來設定。 這是為管線 name 屬性指定的值,其會儲存至 BUILD_BUILDNUMBER 環境變數)。 請確定所使用的組建編號包含適當的 SemVer,例如 1.0.$(Rev:r)。 使用 byBuildNumber 時,工作會從組建編號字串中擷取虛線版本 1.2.3.4,並只使用該部分。 字串的其餘部分將會卸除。 如果您要如往般使用組建編號,可以使用如上所述 byEnvVar,並將 versionEnvVar 設定為 BUILD_BUILDNUMBER

從NuGetInstaller@0或NuGetRestore@1移轉

NuGetInstaller@0NuGetRestore@1 已被取代,您應該以 NuGetCommand@2取代管線中的它們。

如果您使用 NuGetInstaller@0 搭配 restoreMode: restore,請在使用 NuGetCommand@2時設定下列輸入。

NuGetCommand@2工作輸入 價值
command restore
restoreSolution 路徑.sln檔案

如果您使用 NuGetInstaller@0 搭配 restoreMode: install,請在使用 NuGetCommand@2時設定下列輸入。

NuGetCommand@2工作輸入 價值
command custom
arguments NuGet CLI 中完整安裝命令的外觀。 例如,如果您想要在管線中執行相當於 nuget install ninject -OutputDirectory c:\proj,則 arguments 參數會 install ninject -OutputDirectory c:\proj。 如果您使用 NuGetInstaller@0nuGetRestoreArgs 參數,這些參數現在也會進入 arguments

如果您使用 NuGetRestore@1,請在使用 NuGetCommand@2時設定下列輸入。

NuGetCommand@2工作輸入 價值
command restore
restoreSolution 路徑.sln檔案

與使用 NuGetRestore@1NuGetInstaller@0restore 選項類似,NuGetCommand@2 有輸入來設定摘要、在 selectconfig之間決定、指定 NuGet.config 檔案的路徑,以及使用來自 nuget.org 的套件。

如需詳細資訊,請參閱下列 範例

支援較新的Ubuntu裝載映像

從Ubuntu 24.04開始,Microsft裝載的代理程式 不會隨附mono,執行可支援 NuGetCommand@2的基礎 NuGet 用戶端。 Ubuntu 上這項工作的用戶應該使用 .NET CLI 移轉至長期支援的跨平臺工作 NuGetAuthenticate@1

移轉至 Ubuntu 上的 .NET CLI

NuGet 驗證 工作會處理將認證插入用戶端工具以管線身分識別進行驗證所需的位置。 如需搭配 dotnet 使用 NuGet Authenticate 的指示、常見問題和範例,請參閱連結的檔。

如果 dotnet CLI 命令 不支援您的案例,請 向 .NET CLI 小組回報此問題,。 您可以繼續 將代理程式映像 釘選到 Ubuntu 22.04 或更早版本。 Ubuntu 22.04 支援將會繼續,直到Ubuntu26.04正式推出,且不超過2026年。

例子

恢復

使用所選摘要中的套件還原所有解決方案。

# Restore from a project scoped feed in the same organization
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    feedsToUse: 'select'
    vstsFeed: 'my-project/my-project-scoped-feed'
    includeNuGetOrg: false
    restoreSolution: '**/*.sln'
# Restore from an organization scoped feed in the same organization
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    feedsToUse: 'select'
    vstsFeed: 'my-organization-scoped-feed'
    restoreSolution: '**/*.sln'
# Restore from a feed in a different organization
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    feedsToUse: config
    nugetConfigPath: ./nuget.config
    restoreSolution: '**/*.sln'
    externalFeedCredentials: 'MyServiceConnectionName'
    noCache: true
  continueOnError: true
# Restore from feed(s) set in nuget.config
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    feedsToUse: 'config'
    nugetConfigPath: 'nuget.config'

在目的地資料夾中建立 NuGet 套件。

# Package a project
- task: NuGetCommand@2
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    packDestination: '$(Build.ArtifactStagingDirectory)'

注意

管線成品會下載至 Pipeline.Workspace 目錄,以及傳統發行管線的 System.ArtifactsDirectory 目錄。 packagesToPush 值可以分別設定為 $(Pipeline.Workspace)/**/*.nupkg$(System.ArtifactsDirectory)/**/*.nupkg

  • 將套件推送/發佈至 NuGet.config中定義的摘要。

    # Push a project
    - task: NuGetCommand@2
      inputs:
        command: 'push'
        packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg'
        feedsToUse: 'config'
        nugetConfigPath: '$(Build.WorkingDirectory)/NuGet.config'
    
  • 將套件推送/發佈至組織範圍的摘要

    # Push a project
    - task: NuGetCommand@2
      inputs:
        command: 'push'
        nuGetFeedType: 'internal'
        publishVstsFeed: 'my-organization-scoped-feed'
    
  • 將套件推送/發佈至專案範圍摘要

    # Push a project
    - task: NuGetCommand@2
      inputs:
        command: 'push'
        nuGetFeedType: 'internal'
        publishVstsFeed: 'my-project/my-project-scoped-feed'
    
  • 將套件推送/發佈至 NuGet.org

    # Push a project
    - task: NuGetCommand@2
      inputs:
        command: 'push'
        feedsToUse: 'config'
        includeNugetOrg: 'true'
    

習慣

除了預設的 NuGet 命令之外,請執行任何其他 NuGet 命令:套件、推送和還原。

# list local NuGet resources.
- task: NuGetCommand@2
  displayName: 'list locals'
  inputs:
    command: custom
    arguments: 'locals all -list'

要求

要求 描述
管線類型 YAML、傳統組建、傳統版本
執行於 Agent、DeploymentGroup
需求 沒有
功能 此工作不符合作業中後續工作的任何需求。
命令限制 任何
Settable 變數 任何
代理程式版本 2.144.0 或更新
工作類別
要求 描述
管線類型 YAML、傳統組建、傳統版本
執行於 Agent、DeploymentGroup
需求 沒有
功能 此工作不符合作業中後續工作的任何需求。
命令限制 任何
Settable 變數 任何
代理程式版本 2.115.0 或更新
工作類別