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. 
    #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. 必需。 允许的值: restorepackpushcustom。 默认值: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.config、 或 project.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 遇到冲突,任务将失败。 如果位于代理环境中,此选项将不起作用,并且发布将失败。


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-datetime符合 SemVer 的版本,可在其中指定 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

X版本 X.Y.Z 中的


minorVersion -
输入别名: requestedMinorVersionstring. 当 versioningScheme = byPrereleaseNumber && command = pack 时,需要此选项。 默认值:0

Y版本 X.Y.Z 中的


patchVersion - 补丁
输入别名: requestedPatchVersionstring. 当 versioningScheme = byPrereleaseNumber && command = pack 时,需要此选项。 默认值:0

Z版本 X.Y.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 对的列表,用分号分隔,其中文件中.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 存储库进行身份验证的一种新的建议方式。 此任务不再使用新功能,并且仅解决关键 bug。

使用此任务安装和更新 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中将其替换为 。

如果使用 ,restoreMode: restore请在NuGetInstaller@0使用 NuGetCommand@2时配置以下输入。

NuGetCommand@2任务输入
command restore
restoreSolution 路径.sln文件

如果使用 ,restoreMode: install请在NuGetInstaller@0使用 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具有用于设置源、在 或 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'
    

自定义

运行除默认 NuGet 命令之外的任何其他 NuGet 命令:pack、push 和 restore。

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

要求

要求 说明
管道类型 YAML、经典版本、经典版本
运行平台 Agent、DeploymentGroup
需求
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任意
可设置变量 任意
代理版本 2.144.0 或更高版本
任务类别
要求 说明
管道类型 YAML、经典版本、经典版本
运行平台 Agent、DeploymentGroup
需求
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任意
可设置变量 任意
代理版本 2.115.0 或更高版本
任务类别