使用此工作來還原、封裝或推送 NuGet 套件,或執行 NuGet 命令。 此工作支援 NuGet.org 和已驗證的摘要,例如 Azure Artifacts 和 MyGet。 此工作也會使用 NuGet.exe,並與 .NET Framework 應用程式搭配使用。 針對 .NET Core 和 .NET Standard 應用程式,請使用 .NET Core 工作。
Tip
在此任務之前,在管道中使用 NuGetAuthenticate@1 。 有關更多資訊,請參閱 為什麼我的構建管道失敗並提示進行單 Sign-On (SSO) 身份驗證?。
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. 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.
Inputs
command
-
命令
string。 Required. 允許的值:restore、pack、push、custom。 預設值:restore。
指定要執行的 NuGet 命令。 使用 custom 值來新增自變數或使用不同的命令。
restoreSolution
-
解決方案路徑、packages.config或 project.json
輸入別名: solution。
string。
command = restore時為必要項。 預設值:**/*.sln。
指定參考要還原之封裝的方案路徑、packages.config或 project.json 檔案。
使用的 feedsToUse - 摘要
輸入別名: selectOrConfig。
string。
command = restore時為必要項。 允許的值:select(摘要)我在這裡選取),config(我的 NuGet.config中的摘要)。 預設值:select。
指定 Azure Artifacts 和/或 NuGet.org 的摘要,讓工作與 select 值搭配使用。 或者,您可以將 NuGet.config 檔案認可至原始程式碼存放庫,並使用 config 值將其路徑設定為值。
vstsFeed
-
使用此 Azure Artifacts/TFS 摘要中的套件。從下拉式清單中選取 ,或輸入 [項目名稱/]摘要名稱。
輸入別名: feedRestore。
string。 Optional.
selectOrConfig = select && command = restore時使用 。
在產生的 NuGet.config中指定選取的摘要。 您必須安裝套件管理並獲授權,才能在這裡指定摘要。
vstsFeed
-
使用此 Azure Artifacts/TFS 摘要中的套件
輸入別名: feedRestore。
string。 Optional.
selectOrConfig = select && command = restore時使用 。
在產生的 NuGet.config中指定選取的摘要。 您必須安裝套件管理並獲授權,才能在這裡指定摘要。
includeNuGetOrg
-
使用來自 NuGet.org的套件
boolean。 Optional.
selectOrConfig = select && command = restore時使用 。 預設值:true。
在產生的 NuGet.config中包含 NuGet.org。
nugetConfigPath
-
NuGet.config 的路徑
string。 Optional.
selectOrConfig = config && command = restore時使用 。
指定存放庫中 NuGet.config 的路徑,以決定要從中還原封裝的摘要。
externalFeedCredentials
-
此組織/集合外部摘要的認證
輸入別名: externalEndpoints。
string。 Optional.
selectOrConfig = config && command = restore時使用 。
指定要用於位於所選 NuGet.config之外部登錄的認證。 這是 NuGet 服務連線的名稱。 針對此組織或集合中的摘要,請將此保留空白;會自動使用組建的認證。
noCache
-
停用本機快取
boolean。 Optional.
command = restore時使用 。 預設值:false。
當設定為 true時,防止 NuGet 使用本機電腦快取中的套件。
disableParallelProcessing
-
停用平行處理
boolean。 Optional.
command = restore時使用 。 預設值:false。
當設定為 true時,防止 NuGet 在平行進程中安裝多個套件。
restoreDirectory
-
目標目錄
輸入別名: packagesDirectory。
string。 Optional.
command = restore時使用 。
指定安裝套件的資料夾。 如果未指定資料夾,封裝會還原至 packages/ 資料夾,以及選取的解決方案、packages.config或 project.json。
verbosityRestore
-
冗長
string。 Optional.
command = restore時使用 。 允許的值:Quiet、Normal、Detailed。 預設值:Detailed。
指定輸出中顯示的詳細數據量。
packagesToPush
-
發佈 的 NuGet 套件路徑
輸入別名: searchPatternPush。
string。
command = push時為必要項。 預設值:$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg。
指定要比對的模式,或要上傳 nupkg 檔案的路徑。 多個模式可以以分號分隔。
nuGetFeedType
-
目標摘要位置
string。
command = push時為必要項。 允許的值:internal(此組織/集合)、external(外部 NuGet 伺服器(包括其他帳戶/集合)。 預設值:internal。
指定目標摘要是內部摘要/集合或外部 NuGet 伺服器。
publishVstsFeed
-
目標資訊流
輸入別名: feedPublish。
string。
command = push && nuGetFeedType = internal時為必要項。
指定裝載在此帳戶中的摘要。 您必須安裝 Azure Artifacts 並獲授權,才能在這裡選取摘要。
publishPackageMetadata
-
發佈管線元數據
boolean。 Optional.
command = push && nuGetFeedType = internal時使用 。 預設值:true。
變更一組持續發行套件內已變更套件子集的版本號碼。
allowPackageConflicts
-
允許略過重複專案
boolean。 Optional.
command = push && nuGetFeedType = internal時使用 。 預設值:false。
即使某些套件遭到拒絕且發生 409 衝突錯誤,仍會報告工作成功。
此選項目前僅適用於 Azure Pipelines 和 Windows 代理程式。 如果 NuGet.exe 發生衝突,工作將會失敗。 如果您位於 Proxy 環境中,此選項將無法運作,而且發佈將會失敗。
publishFeedCredentials
-
NuGet 伺服器
輸入別名: externalEndpoint。
string。
command = push && nuGetFeedType = external時為必要項。
指定包含外部 NuGet 伺服器認證的 NuGet 服務連線。
verbosityPush
-
冗長
string。 Optional.
command = push時使用 。 允許的值:Quiet、Normal、Detailed。 預設值:Detailed。
指定輸出中顯示的詳細數據量。
packagesToPack
-
csproj 或 nuspec 檔案的路徑以封裝
輸入別名: searchPatternPack。
string。
command = pack時為必要項。 預設值:**/*.csproj。
指定工作用來搜尋要封裝之 csproj 目錄的模式。
您可以使用分號分隔多個模式,並以 !做為負數。 範例:**\*.csproj;!**\*.Tests.csproj。
configuration
-
組態封裝
輸入別名: configurationToPack。
string。 Optional.
command = pack時使用 。 預設值:$(BuildConfiguration)。
指定使用 csproj 檔案時要封裝的組態。
packDestination
-
包資料夾
輸入別名: outputDir。
string。 Optional.
command = pack時使用 。 預設值:$(Build.ArtifactStagingDirectory)。
指定工作建立封裝的資料夾。 如果值是空的,工作會在來源根目錄建立套件。
versioningScheme
-
自動套件版本設定
string。
command = pack時為必要項。 允許的值:off、byPrereleaseNumber(使用日期和時間)、byEnvVar(使用環境變數)、byBuildNumber(使用組建編號)。 預設值:off。
根據指定的值套用自動套件版本設定。 此字串無法與 includeReferencedProjects搭配使用。 允許的值為:
-
byPrereleaseNumber- 使用日期和時間:工作會產生格式化為X.Y.Z-ci-datetime相容版本,您可以在其中指定 X、Y 和 Z 的值。 -
byEnvVar- 使用環境變數:工作會使用您指定的環境變數,並包含您想要使用的版本號碼。 -
byBuildNumber- 使用組建編號:工作會使用組建編號來建立套件的版本。
Note
在 [一般] 下,將組建格式設定為 $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)。
includeReferencedProjects
-
包含參考的專案
boolean。 Optional.
versioningScheme = off && command = pack時使用 。 預設值:false。
包含參考的專案為相依性或封裝的一部分。 無法搭配自動套件版本設定使用。 如果參考的專案具有與專案同名的對應 nuspec 檔案,則會將參考的專案新增為相依性。 否則,參考的專案會新增為封裝的一部分。 深入瞭解 如何使用 NuGet CLI 的 pack 命令建立 NuGet 套件。
versionEnvVar
-
環境變數
string。
versioningScheme = byEnvVar && command = pack時為必要項。
指定變數名稱,而不 $、$env或 %。
majorVersion
-
主要
輸入別名: requestedMajorVersion。
string。
versioningScheme = byPrereleaseNumber && command = pack時為必要項。 預設值:1。
X在版本 X.Y.Z.
minorVersion
-
次要
輸入別名: requestedMinorVersion。
string。
versioningScheme = byPrereleaseNumber && command = pack時為必要項。 預設值:0。
Y在版本 X.Y.Z.
patchVersion
-
補丁
輸入別名: requestedPatchVersion。
string。
versioningScheme = byPrereleaseNumber && command = pack時為必要項。 預設值:0。
Z在版本 X.Y.Z.
packTimezone
-
時區
string。 Optional.
versioningScheme = byPrereleaseNumber && command = pack時使用 。 允許的值:utc、local(代理程式當地時間)。 預設值:utc。
指定用來產生封裝版本所需的時區。 如果您使用裝載的組建代理程序,建議您選取 utc,因為其日期和時間可能會有所不同。
includeSymbols
-
建立符號套件
boolean。 Optional.
command = pack時使用 。 預設值:false。
指定封裝包含來源和符號。 與 .nuspec 檔案搭配使用時,這會建立一般 NuGet 套件檔案和對應的符號套件。
toolPackage
-
工具包
boolean。 Optional.
command = pack時使用 。 預設值:false。
判斷項目的輸出檔是否應該位於工具資料夾中。
buildProperties
-
其他組建屬性
string。 Optional.
command = pack時使用 。
指定以分號分隔的 token=value 配對清單,其中 $token$ 檔案中出現的每個 .nuspec 都會取代為指定的值。 值可以是引號中的字串。
basePath
-
基本路徑
string。 Optional.
command = pack時使用 。
指定 nuspec 檔案中定義的檔案基底路徑。
verbosityPack
-
冗長
string。 Optional.
command = pack時使用 。 允許的值:Quiet、Normal、Detailed。 預設值:Detailed。
指定輸出中顯示的詳細數據量。
arguments
-
命令和自變數
string。
command = custom時為必要項。
指定將傳遞至 NuGet.exe 執行的命令和自變數。 如果使用 NuGet 3.5 或更新版本,則會針對此組織或集合中專案集合建置服務有權存取的任何摘要,list、restore和 publish 等已驗證的命令。
工作控制選項
除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制項選項和一般工作屬性。
輸出變數
None.
Remarks
Important
如果要使用 Azure Artifacts 或其他 NuGet 儲存庫進行身份驗證,則必須使用 NuGet 身份驗證 任務而不是 NuGetCommand@2 任務。 該 NuGetCommand@2 任務不再使用新功能進行更新;僅處理關鍵錯誤。
使用此任務可以還原、打包或推送 NuGet 包,或者運行 NuGet 命令。 此任務使用 NuGet.exe 並適用於 .NET Framework 應用。 如果使用的是 .NET Core 或 .NET Standard,請使用 .NET Core 任務,該任務完全支援所有包方案,目前受 dotnet 支援。
如果您的代碼依賴於 NuGet 包,並且您需要在使用 Visual Studio 生成任務 任務構建專案之前還原這些依賴項,則可以使用 nugetAuthenticate 和 命令行 任務來還原包。 將這兩個任務放在構建步驟之前,以確保所有依賴項在構建開始之前都可用。 有關更多詳細資訊,請參閱 還原 NuGet 包 。
使用 Visual Studio 生成任務 任務時,請確保將 restoreNugetPackages 參數留空,因為“還原 NuGet 包”選項在 VSBuild@1 任務中已棄用。
Tip
此版本的 NuGet 工作預設會使用 NuGet 4.1.0。 若要選擇其他版本的 NuGet,請使用 工具安裝程式。
版本設定配置
對於 byPrereleaseNumber,版本將設置為您為主要版本、次要版本和修補程式選擇的值,以及日期和時間,格式 yyyymmdd-hhmmss為 。
對於 byEnvVar,版本將設置為具有 versionEnvVar 參數指定名稱的環境變數的值,例如 MyVersion (no $,只是環境變數名稱)。 請確定環境變數已設定為適當的 SemVer,例如 1.2.3 或 1.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@0 和 NuGetRestore@1 已被取代,您應該以 NuGetCommand@2取代管線中的它們。
如果您使用 NuGetInstaller@0 搭配 restoreMode: restore,請在使用 NuGetCommand@2時設定下列輸入。
| NuGetCommand@2工作輸入 | Value |
|---|---|
command |
restore |
restoreSolution |
路徑.sln檔案 |
如果您使用 NuGetInstaller@0 搭配 restoreMode: install,請在使用 NuGetCommand@2時設定下列輸入。
| NuGetCommand@2工作輸入 | Value |
|---|---|
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工作輸入 | Value |
|---|---|
command |
restore |
restoreSolution |
路徑.sln檔案 |
與使用 NuGetRestore@1 或 NuGetInstaller@0restore 選項類似,NuGetCommand@2 有輸入來設定摘要、在 select 或 config之間決定、指定 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年。
為什麼我的構建管道失敗並提示進行單 Sign-On (SSO) 身份驗證?
如果憑證過期,構建可能會失敗。 若要避免這些失敗,建議使用 NuGet 身份驗證 任務重新安裝憑據提供程式並自動刷新憑據。 這可確保在管道執行期間不間斷地訪問。
steps:
# Authenticate with NuGet to ensure credentials are refreshed
- task: NuGetAuthenticate@1
# Restore NuGet packages
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
Examples
Restore
使用所選摘要中的套件還原所有解決方案。
# 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'
Package
在目的地資料夾中建立 NuGet 套件。
# Package a project
- task: NuGetCommand@2
inputs:
command: 'pack'
packagesToPack: '**/*.csproj'
packDestination: '$(Build.ArtifactStagingDirectory)'
推送
Note
管線成品會下載至 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'
Requirements
| Requirement | Description |
|---|---|
| 管道類型 | YAML、傳統組建、傳統版本 |
| 運行 | 代理、部署組 |
| Demands | None |
| Capabilities | 此工作不符合作業中後續工作的任何需求。 |
| 命令限制 | Any |
| 可設置變數 | Any |
| 代理程式版本 | 2.144.0 或更新 |
| 任務類別 | Package |
| Requirement | Description |
|---|---|
| 管道類型 | YAML、傳統組建、傳統版本 |
| 運行 | 代理、部署組 |
| Demands | None |
| Capabilities | 此工作不符合作業中後續工作的任何需求。 |
| 命令限制 | Any |
| 可設置變數 | Any |
| 代理程式版本 | 2.115.0 或更新 |
| 任務類別 | Package |