NuGetCommand@2 - NuGet v2 工作

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

Syntax

# 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 && command = push. 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. 必要。 允許的值:restore、、、packpushcustom 預設值:restore

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


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

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


feedsToUse - 要使用的摘要
輸入別名: selectOrConfigstring. 當 command = 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中指定選取的摘要。 您必須安裝套件管理並取得授權,才能在此指定摘要。


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.configproject.json一起還原到packages/資料夾。


verbosityRestore - 冗長
string. 選擇性。 使用時機 command = restore。 允許值:QuietNormalDetailed。 預設值:Detailed

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


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

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


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

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


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

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


publishVstsFeed - 目標摘要
輸入別名: feedPublishstring. 當 command = push && nuGetFeedType = internal 時為必要。

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


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

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


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

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

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


publishFeedCredentials - NuGet 伺服器
輸入別名: externalEndpointstring. 當 command = push && nuGetFeedType = external 時為必要。

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


verbosityPush - 冗長
string. 選擇性。 使用 時 command = push。 允許值:QuietNormalDetailed。 預設值:Detailed

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


packagesToPack - csproj 或 nuspec 檔案的路徑 (要封裝的)
輸入別名: searchPatternPackstring. 當 command = pack 時為必要。 預設值:**/*.csproj

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

您可以使用分號分隔多個模式,並以 前置詞來建立模式負 !數。 範例: **\*.csproj;!**\*.Tests.csproj.


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

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


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

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


versioningScheme - 自動套件版本控制
string. 當 command = pack 時為必要。 允許的值: offbyPrereleaseNumber (使用日期和時間) , byEnvVar (使用環境變數) , byBuildNumber (使用組建編號) 。 預設值:off

根據指定的值套用自動套件版本設定。 此字串不能搭配 使用 includeReferencedProjects。 允許的值包括:

  • byPrereleaseNumber - 使用日期和時間:工作會產生格式化為 X.Y.Z-ci-datetimeSemVer 相容版本,您可以在其中指定 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 - 環境變數
string. 當 versioningScheme = byEnvVar && command = pack 時為必要。

指定不含 $$env%的變數名稱。


majorVersion - 主要
輸入別名: requestedMajorVersionstring. 當 versioningScheme = byPrereleaseNumber && command = pack 時為必要。 預設值:1

XX.Y.Z 版中的 。


minorVersion -
輸入別名: requestedMinorVersionstring. 當 versioningScheme = byPrereleaseNumber && command = pack 時為必要。 預設值:0

YX.Y.Z 版中的 。


patchVersion - 補丁
輸入別名: requestedPatchVersionstring. 當 versioningScheme = byPrereleaseNumber && command = pack 時為必要。 預設值:0

ZX.Y.Z 版中的 。


packTimezone - 時區
string. 選擇性。 使用 時 versioningScheme = byPrereleaseNumber && command = pack。 允許的值: utclocal (Agent 當地時間) 。 預設值:utc

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


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

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


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

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


buildProperties - 其他建置屬性
string. 選擇性。 使用時機 command = pack

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


basePath - 基底路徑
string. 選擇性。 使用時機 command = pack

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


verbosityPack - 冗長
string. 選擇性。 使用時機 command = pack。 允許值:QuietNormalDetailed。 預設值:Detailed

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


arguments - 命令和自變數
string. 當 command = 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,請使用 工具安裝程式

版本設定配置

針對 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檔案

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

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

範例

還原

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

# 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'
    

Custom

執行預設 NuGet 命令以外的任何其他 NuGet 命令:套件、推送和還原。

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

規格需求

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