DotNetCoreCLI@2 - .NET Core v2 任务

生成、测试、打包或发布 dotnet 应用程序,或运行自定义 dotnet 命令。

生成、测试、打包或发布 dotnet 应用程序,或运行自定义 dotnet 命令。 对于包命令,支持 NuGet.org 和经过身份验证的源(例如包管理和 MyGet)。

重要

NuGet 身份验证任务是使用 Azure Artifacts 和其他 NuGet 存储库进行身份验证的一种新的建议方式。 restore此 .NET Core CLI 任务的 和 push 命令不再采用新功能,仅解决关键 bug。 有关详细信息,请参阅备注。

语法

# .NET Core v2
# Build, test, package, or publish a dotnet application, or run a custom dotnet command.
- task: DotNetCoreCLI@2
  inputs:
    command: 'build' # 'build' | 'push' | 'pack' | 'publish' | 'restore' | 'run' | 'test' | 'custom'. Required. Command. Default: build.
    #publishWebProjects: true # boolean. Optional. Use when command = publish. Publish web projects. Default: true.
    #projects: # string. Optional. Use when command = build || command = restore || command = run || command = test || command = custom || publishWebProjects = false. Path to project(s) or solution(s). 
    #custom: # string. Required when command = custom. Custom command. 
    #arguments: # string. Optional. Use when command = build || command = publish || command = run || command = test || command = custom. Arguments. 
    #restoreArguments: # string. Optional. Use when command = restore. Arguments. 
    #publishTestResults: true # boolean. Optional. Use when command = test. Publish test results and code coverage. Default: true.
    #testRunTitle: # string. Optional. Use when command = test. Test run title. 
    #zipAfterPublish: true # boolean. Optional. Use when command = publish. Zip published projects. Default: true.
    #modifyOutputPath: true # boolean. Optional. Use when command = publish. Add project's folder name to publish path. Default: true.
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' # string. Alias: searchPatternPush. Required when command = push. Path to NuGet package(s) to publish. Default: $(Build.ArtifactStagingDirectory)/*.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. 
    #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).
    #packDirectory: '$(Build.ArtifactStagingDirectory)' # string. Alias: outputDir. Optional. Use when command = pack. Package Folder. Default: $(Build.ArtifactStagingDirectory).
    #nobuild: false # boolean. Optional. Use when command = pack. Do not build. Default: false.
    #includesymbols: false # boolean. Optional. Use when command = pack. Include Symbols. Default: false.
    #includesource: false # boolean. Optional. Use when command = pack. Include Source. Default: false.
  # 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 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.
    #restoreDirectory: # string. Alias: packagesDirectory. Optional. Use when command = restore. Destination directory. 
    #verbosityRestore: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. 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.
  # Pack options
    #versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required when command = pack. Automatic package versioning. Default: off.
    #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.
  # Advanced
    #buildProperties: # string. Optional. Use when command = pack. Additional build properties. 
    #verbosityPack: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Optional. Use when command = pack. Verbosity. Default: Detailed.
  # Advanced
    #workingDirectory: # string. Optional. Use when command != restore && command != push && command != pack && command != pack && command != push && command != restore. Working directory.
# .NET Core v2
# Build, test, package, or publish a dotnet application, or run a custom dotnet command.
- task: DotNetCoreCLI@2
  inputs:
    command: 'build' # 'build' | 'push' | 'pack' | 'publish' | 'restore' | 'run' | 'test' | 'custom'. Required. Command. Default: build.
    #publishWebProjects: true # boolean. Optional. Use when command = publish. Publish web projects. Default: true.
    #projects: # string. Optional. Use when command = build || command = restore || command = run || command = test || command = custom || publishWebProjects = false. Path to project(s). 
    #custom: # string. Required when command = custom. Custom command. 
    #arguments: # string. Optional. Use when command = build || command = publish || command = run || command = test || command = custom. Arguments. 
    #restoreArguments: # string. Optional. Use when command = restore. Arguments. 
    #publishTestResults: true # boolean. Optional. Use when command = test. Publish test results and code coverage. Default: true.
    #testRunTitle: # string. Optional. Use when command = test. Test run title. 
    #zipAfterPublish: true # boolean. Optional. Use when command = publish. Zip published projects. Default: true.
    #modifyOutputPath: true # boolean. Optional. Use when command = publish. Add project's folder name to publish path. Default: true.
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' # string. Alias: searchPatternPush. Required when command = push. Path to NuGet package(s) to publish. Default: $(Build.ArtifactStagingDirectory)/*.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. 
    #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).
    #packDirectory: '$(Build.ArtifactStagingDirectory)' # string. Alias: outputDir. Optional. Use when command = pack. Package Folder. Default: $(Build.ArtifactStagingDirectory).
    #nobuild: false # boolean. Optional. Use when command = pack. Do not build. Default: false.
    #includesymbols: false # boolean. Optional. Use when command = pack. Include Symbols. Default: false.
    #includesource: false # boolean. Optional. Use when command = pack. Include Source. Default: false.
  # 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 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.
    #restoreDirectory: # string. Alias: packagesDirectory. Optional. Use when command = restore. Destination directory. 
    #verbosityRestore: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. 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.
  # Pack options
    #versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required when command = pack. Automatic package versioning. Default: off.
    #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.
  # Advanced
    #buildProperties: # string. Optional. Use when command = pack. Additional build properties. 
    #verbosityPack: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Optional. Use when command = pack. Verbosity. Default: Detailed.
  # Advanced
    #workingDirectory: # string. Optional. Use when command != restore && command != push && command != pack && command != pack && command != push && command != restore. Working directory.
# .NET Core v2
# Build, test, package, or publish a dotnet application, or run a custom dotnet command.
- task: DotNetCoreCLI@2
  inputs:
    command: 'build' # 'build' | 'push' | 'pack' | 'publish' | 'restore' | 'run' | 'test' | 'custom'. Required. Command. Default: build.
    #publishWebProjects: true # boolean. Optional. Use when command = publish. Publish Web Projects. Default: true.
    #projects: # string. Optional. Use when command = build || command = restore || command = run || command = test || command = custom || publishWebProjects = false. Path to project(s). 
    #custom: # string. Required when command = custom. Custom command. 
    #arguments: # string. Optional. Use when command = build || command = publish || command = run || command = test || command = custom. Arguments. 
    #publishTestResults: true # boolean. Optional. Use when command = test. Publish test results and code coverage. Default: true.
    #testRunTitle: # string. Optional. Use when command = test. Test run title. 
    #zipAfterPublish: true # boolean. Optional. Use when command = publish. Zip Published Projects. Default: true.
    #modifyOutputPath: true # boolean. Optional. Use when command = publish. Add project name to publish path. Default: true.
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' # string. Alias: searchPatternPush. Required when command = push. Path to NuGet package(s) to publish. Default: $(Build.ArtifactStagingDirectory)/*.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. 
    #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).
    #packDirectory: '$(Build.ArtifactStagingDirectory)' # string. Alias: outputDir. Optional. Use when command = pack. Package Folder. Default: $(Build.ArtifactStagingDirectory).
    #nobuild: false # boolean. Optional. Use when command = pack. Do not build. Default: false.
    #includesymbols: false # boolean. Optional. Use when command = pack. Include Symbols. Default: false.
    #includesource: false # boolean. Optional. Use when command = pack. Include Source. Default: false.
  # 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 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.
    #restoreDirectory: # string. Alias: packagesDirectory. Optional. Use when command = restore. Destination directory. 
    #verbosityRestore: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. 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.
  # Pack options
    #versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required when command = pack. Automatic package versioning. Default: off.
    #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.
  # Advanced
    #buildProperties: # string. Optional. Use when command = pack. Additional build properties. 
    #verbosityPack: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Optional. Use when command = pack. Verbosity. Default: Detailed.
  # Advanced
    #workingDirectory: # string. Optional. Use when command != pack && command != push && command != restore. Working Directory.
# .NET Core v2
# Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
- task: DotNetCoreCLI@2
  inputs:
    command: 'build' # 'build' | 'push' | 'pack' | 'publish' | 'restore' | 'run' | 'test' | 'custom'. Required. Command. Default: build.
    #publishWebProjects: true # boolean. Optional. Use when command = publish. Publish Web Projects. Default: true.
    #projects: # string. Optional. Use when command = build || command = restore || command = run || command = test || command = custom || publishWebProjects = false. Path to project(s). 
    #custom: # string. Required when command = custom. Custom command. 
    #arguments: # string. Optional. Use when command = build || command = publish || command = run || command = test || command = custom. Arguments. 
    #publishTestResults: true # boolean. Optional. Use when command = test. Publish test results and code coverage. Default: true.
    #zipAfterPublish: true # boolean. Optional. Use when command = publish. Zip Published Projects. Default: true.
    #modifyOutputPath: true # boolean. Optional. Use when command = publish. Add project name to publish path. Default: true.
    #packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg' # string. Alias: searchPatternPush. Required when command = push. Path to NuGet package(s) to publish. Default: $(Build.ArtifactStagingDirectory)/*.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. 
    #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).
    #packDirectory: '$(Build.ArtifactStagingDirectory)' # string. Alias: outputDir. Optional. Use when command = pack. Package Folder. Default: $(Build.ArtifactStagingDirectory).
    #nobuild: false # boolean. Optional. Use when command = pack. Do not build. Default: false.
  # 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.
    #restoreDirectory: # string. Alias: packagesDirectory. Optional. Use when command = restore. Destination directory. 
    #verbosityRestore: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Optional. Use when command = restore. Verbosity. Default: Detailed.
  # Pack options
    #versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required when command = pack. Automatic package versioning. Default: off.
    #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.
  # Advanced
    #buildProperties: # string. Optional. Use when command = pack. Additional build properties. 
    #verbosityPack: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Optional. Use when command = pack. Verbosity. Default: Detailed.
  # Advanced
    #workingDirectory: # string. Optional. Use when command != pack && command != push && command != restore. Working Directory.

输入

command - 命令
string. 必需。 允许的值:buildpush (nuget push) 、packpublishrestoreruntest、 。 custom 默认值:build

要运行的 dotnet 命令。 指定 custom 以添加参数或使用此处未列出的命令。

重要

NuGet 身份验证任务是使用 Azure Artifacts 和其他 NuGet 存储库进行身份验证的一种新的建议方式。 restore此 .NET Core CLI 任务的 和 push 命令不再采用新功能,仅解决关键 bug。 有关详细信息,请参阅备注。


publishWebProjects - 发布 Web 项目
boolean. 可选。 在 时 command = publish使用 。 默认值:true

如果此输入设置为 true,则会 projects 跳过 属性值,并且任务会尝试在存储库中查找 Web 项目,并对其运行发布命令。 Web 项目通过目录中是否存在 web.config 文件或 wwwroot 文件夹来标识。 如果没有 web.config 文件或 wwwroot 文件夹,则会选择使用 Web SDK(如 Microsoft.NET.Sdk.Web)的项目。


publishWebProjects - 发布 Web 项目
boolean. 可选。 在 时 command = publish使用 。 默认值:true

如果此输入设置为 true,则会 projects 跳过 属性值,并且任务会尝试在存储库中查找 Web 项目,并对其运行发布命令。 Web 项目通过目录中是否存在 web.config 文件或 wwwroot 文件夹来标识。 如果没有 web.config 文件或 wwwroot 文件夹,则会选择使用 Web SDK(如 Microsoft.NET.Sdk.Web)的项目。


projects - 项目 () 或解决方案 () 的路径
string. 可选。 在 时 command = build || command = restore || command = run || command = test || command = custom || publishWebProjects = false使用 。

.csproj) 使用的 或 .sln 文件的路径 (。 可以使用通配符 (例如 **/*.csproj 为所有子文件夹中的所有 .csproj 文件) 。 有关详细信息,请参阅 文件匹配模式参考

无论设置如何 workingDirectory ,此路径都相对于存储库的根目录。


projects - 项目 () 的路径
string. 可选。 在 时 command = build || command = restore || command = run || command = test || command = custom || publishWebProjects = false使用 。

() 使用的文件的路径 .csproj 。 可以使用通配符 (例如 **/*.csproj 为所有子文件夹中的所有 .csproj 文件) 。 有关详细信息,请参阅 文件匹配模式参考

无论设置如何 workingDirectory ,此路径都相对于存储库的根目录。


custom - 自定义命令
string. 当 command = custom 时,需要此选项。

要传递给 dotnet.exe 以供执行的命令。 有关可用命令的完整列表,请参阅 dotnet CLI 文档


arguments - 参数
string. 可选。 在 时 command = build || command = publish || command = run || command = test || command = custom使用 。

指定所选命令的参数。 例如,生成配置、输出文件夹和运行时。 参数取决于所选的命令。

此输入当前仅接受 、、publishruntestcustom的参数build。 如果要为未列出的命令添加参数,请使用 custom


restoreArguments - 参数
string. 可选。 在 时 command = restore使用 。

写入要传递给 restore 命令的其他参数。


publishTestResults - 发布测试结果和代码覆盖率
boolean. 可选。 在 时 command = test使用 。 默认值:true

启用此选项将在 中$(Agent.TempDirectory)生成 test results TRX 文件,结果将发布到服务器。

此选项将 --logger trx --results-directory $(Agent.TempDirectory) 追加到命令行参数。

可以通过将 选项添加到 --collect "Code coverage" 命令行参数来收集代码覆盖率。


testRunTitle - 测试运行标题
string. 可选。 在 时 command = test使用 。

提供测试运行的名称。


zipAfterPublish - 压缩已发布的项目
boolean. 可选。 在 时 command = publish使用 。 默认值:true

如果此输入设置为 true,则发布命令创建的文件夹将被压缩并删除。


zipAfterPublish - Zip 发布的项目
boolean. 可选。 在 时 command = publish使用 。 默认值:true

如果此输入设置为 true,则发布命令创建的文件夹将被压缩并删除。


modifyOutputPath - 添加项目的文件夹名称以发布路径
boolean. 可选。 在 时 command = publish使用 。 默认值:true

如果此输入设置为 true,则当在参数中显式指定输出路径时,由 publish 命令创建的文件夹名称将为其文件夹名称添加前缀的项目文件名。 如果要将多个项目发布到同一文件夹,这非常有用。


modifyOutputPath - 添加项目名称以发布路径
boolean. 可选。 在 时 command = publish使用 。 默认值:true

如果此输入设置为 true,则当在参数中显式指定输出路径时,由 publish 命令创建的文件夹名称将为其文件夹名称添加前缀的项目文件名。 如果要将多个项目发布到同一文件夹,这非常有用。


feedsToUse - 要使用的源
输入别名: selectOrConfigstring. 当 command = restore 时,需要此选项。 允许的值: select (源 () 我选择此处) , config (NuGet.config) 中的源。 默认值:select

可以从 Azure Artifacts 和/或 NuGet.org 此处选择源,也可以将文件提交 nuget.config 到源代码存储库,并使用 nugetConfigPath 输入设置其路径。


vstsFeed - 使用此 Azure Artifacts 源中的包
输入别名: feedRestorestring. 可选。 在 时 selectOrConfig = select && command = restore使用 。

在生成的 NuGet.config中包含所选源。 必须安装包管理并已获得许可才能在此处选择源。 projectName/feedName 用于项目范围的源。 仅用于 FeedName 组织范围的源。 注意:测试命令不支持此操作。


vstsFeed - 使用此 Azure Artifacts/TFS 源中的包
输入别名: feedRestorestring. 可选。 在 时 selectOrConfig = select && command = restore使用 。

在生成的 NuGet.config中包含所选源。 必须安装包管理并已获得许可才能在此处选择源。 projectName/feedName 用于项目范围的源。 仅用于 FeedName 组织范围的源。 注意:测试命令不支持此操作。


includeNuGetOrg - 使用来自 NuGet.org 的包
boolean. 可选。 在 时 selectOrConfig = select && command = restore使用 。 默认值:true

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


nugetConfigPath - NuGet.config路径
string. 可选。 在 时 selectOrConfig = config && command = restore使用 。

存储库中的 , NuGet.config 指定要从中还原包的源。


externalFeedCredentials - 此组织/集合外部源的凭据
输入别名: externalEndpointsstring. 可选。 在 时 selectOrConfig = config && command = restore使用 。

要用于位于所选 NuGet.config中的外部注册表的凭据。 对于此组织/集合中的源,将此输入留空;将自动使用生成的凭据。


noCache - 禁用本地缓存
boolean. 可选。 在 时 command = restore使用 。 默认值:false

防止 NuGet 使用本地计算机缓存中的包。


restoreDirectory - 目标目录
输入别名: packagesDirectorystring. 可选。 在 时 command = restore使用 。

指定要在其中安装包的文件夹。 如果未指定任何文件夹,包将还原到默认 NuGet 包缓存中。


verbosityRestore - 冗长
string. 可选。 在 时 command = restore使用 。 允许的值:-Quiet、、MinimalNormalDetailedDiagnostic。 默认值:Detailed

指定要在 restore 命令输出中显示的详细信息量。


packagesToPush - 要发布的 NuGet 包 () 的路径
输入别名: searchPatternPushstring. 当 command = push 时,需要此选项。 默认值:$(Build.ArtifactStagingDirectory)/*.nupkg

要匹配的模式或要上载的文件的路径 nupkg 。 多个模式可以用分号分隔,并且可以通过为 !模式添加前缀来使模式为负。 示例:**/*.nupkg;!**/*.Tests.nupkg


nuGetFeedType - 目标源位置
string. 当 command = push 时,需要此选项。 允许的值: internal (此组织/集合) , external (外部 NuGet 服务器 (包括其他组织/集合) ) 。 默认值:internal

指定目标源是内部源还是外部源。


publishVstsFeed - 目标源
输入别名: feedPublishstring. 当 command = push && nuGetFeedType = internal 时,需要此选项。

指定在此组织中托管的源。 必须安装包管理并已获得许可才能在此处选择源。


publishPackageMetadata - 发布管道元数据
boolean. 可选。 在 时 command = push && nuGetFeedType = internal && command = push使用 。 默认值:true

将此生成/发布管道的元数据 (运行 #、源代码信息) 与包相关联。


publishFeedCredentials - NuGet 服务器
输入别名: externalEndpointstring. 当 command = push && nuGetFeedType = external 时,需要此选项。

包含外部 NuGet 服务器凭据的 NuGet 服务连接


packagesToPack - 要打包的 csproj 或 nuspec 文件 () 的路径
输入别名: searchPatternPackstring. 当 command = pack 时,需要此选项。 默认值:**/*.csproj

要搜索 .csproj.nuspec 要打包的文件的模式。

可以使用分号分隔多个模式,并且可以通过为模式添加 !前缀来使模式为负。 示例:**/*.csproj;!**/*.Tests.csproj


configuration - 配置到包
输入别名: configurationToPackstring. 可选。 在 时 command = pack使用 。 默认值:$(BuildConfiguration)

使用 .csproj 文件时,此输入指定要打包的配置。


packDirectory - 包文件夹
输入别名: outputDirstring. 可选。 在 时 command = pack使用 。 默认值:$(Build.ArtifactStagingDirectory)

将在其中创建包的文件夹。 如果此文件夹为空,则将在文件旁边 csproj 创建包。


nobuild - 不生成
boolean. 可选。 在 时 command = pack使用 。 默认值:false

指定任务在打包之前不会生成项目。 此任务对应于 --no-build 命令的 build 参数。


includesymbols - 包含符号
boolean. 可选。 在 时 command = pack使用 。 默认值:false

创建符号 NuGet 包。 此任务对应于 --include-symbols 命令行参数。


includesource - 包含源
boolean. 可选。 在 时 command = pack使用 。 默认值:false

在包中包含源代码。 此任务对应于 --include-source 命令行参数。


versioningScheme - 自动包版本控制
string. 当 command = pack 时,需要此选项。 允许的值: offbyPrereleaseNumber (使用日期和时间) , byEnvVar (使用环境变量) , byBuildNumber (使用内部版本号) 。 默认值:off

此任务不能与包含的引用项目一起使用。 如果选择 Use the date and time,这将生成一个符合 SemVer 的版本,格式为 X.Y.Z-ci-datetime 选择 XYZ的位置。

如果选择 Use an environment variable,则必须选择环境变量,并确保它包含要使用的版本号。

如果选择 Use the build number,将使用内部版本号对包进行版本控制。 注意: 在 下 Options,将内部版本号格式设置为 $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)


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 中的 。


buildProperties - 其他生成属性
string. 可选。 在 时 command = pack使用 。

指定用分号分隔的token = value对列表,其中文件中出现的每个匹配$token$.nuspec项都将替换为给定值。 值可以是引号中的字符串。


verbosityPack - 冗长
string. 可选。 在 时 command = pack使用 。 允许的值:-Quiet、、MinimalNormalDetailedDiagnostic。 默认值:Detailed

指定要在 pack 命令输出中显示的详细信息量。


workingDirectory - 工作目录
string. 可选。 在 时 command != restore && command != push && command != pack && command != pack && command != push && command != restore使用 。

运行脚本的当前工作目录。 Empty 是存储库 (生成) 或项目 (发布) 的根,即 $(System.DefaultWorkingDirectory)


workingDirectory - 工作目录
string. 可选。 在 时 command != pack && command != push && command != restore使用 。

运行脚本的当前工作目录。 Empty 是存储库 (生成) 或项目 (发布) 的根,即 $(System.DefaultWorkingDirectory)


任务控制选项

除了任务输入,所有任务都有控制选项。 有关详细信息,请参阅 控制选项和常见任务属性

输出变量

无。

备注

重要

NuGet 身份验证任务是使用 Azure Artifacts 和其他 NuGet 存储库进行身份验证的一种新的建议方式。 restore此 .NET Core CLI 任务的 和 push 命令不再采用新功能,仅解决关键 bug。

为什么我的生成、发布或测试步骤无法还原包?

大多数 dotnet 命令(包括 buildpublishtest )都包含一个隐式 restore 步骤。 即使你在前面的步骤中成功 dotnet restore 运行了,这也会对经过身份验证的源失败,因为前面的步骤将清理所使用的凭据。

若要解决此问题,请将 --no-restore 标志添加到 Arguments 文本框中。

此外,test命令无法识别 feedRestorevstsFeed 参数,在隐式restore步骤运行时,以这种方式指定的源将不会包含在生成的NuGet.config文件中。 建议使用显式 dotnet restore 步骤来还原包。 命令 restore 遵循 feedRestorevstsFeed 参数。

为什么使用 包源映射 收到 NU1507 警告,但在我的计算机上生成时,它没有警告?

执行 NuGet 还原或访问 NuGet 源的各种命令会生成一个特殊的临时 NuGet.config 文件,该文件为 Azure 项目 NuGet 源添加 NuGet 身份验证。 执行此操作的方式与包源映射用于将包映射到源的架构冲突,并中断存储库中文件中的 NuGet.config 包源映射固定配置。 若要解决此冲突,可以使用 NuGet 身份验证 任务进行身份验证,然后使用自定义命令调用所需的 dotnet 命令,而无需 NuGet.config 修改。

# Authenticate Azure DevOps NuGet feed
- task: NuGetAuthenticate@1
  displayName: 'Authenticate Azure DevOps NuGet feed'

# Restore project
- task: DotNetCoreCLI@2
  inputs:
    command: 'custom'
    custom: 'restore'

# Build project
- task: DotNetCoreCLI@2
  inputs:
    command: 'custom'
    custom: 'build'
    arguments: '--no-restore'

为什么我应该在 NuGet.config 中检查?

NuGet.config 签入源代码管理可确保每个签出代码的开发人员都可以使用生成项目所需的关键信息(包的位置)。

但是,对于开发人员团队处理大量项目的情况,还可以在每个开发人员的计算机上向全局 NuGet.config 添加 Azure Artifacts 源。 在这些情况下,使用 Feeds I select here NuGet 任务中的 选项会复制此配置。

故障排除

使用实体框架的项目已停止在托管代理上工作

.NET Core 没有内置实体框架 (EF) 。 在开始执行之前,必须安装 EF,或者使用所需的 .NET Core SDK 版本添加到 global.json 项目中。 这将确保使用正确的 SDK 生成 EF 项目。 如果计算机上不存在所需的版本,请将 UseDotNetV2 任务添加到管道以安装所需的版本。 有关详细信息,请参阅 获取 Entity Framework Core 运行时

示例

生成示例

生成项目

# Build project
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'

生成多个项目

# Build multiple projects
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: |
      src/proj1/proj1.csproj 
      src/proj2/proj2.csproj 
      src/other/other.sln    # Pass a solution instead of a csproj.

推送示例

将 NuGet 包推送到内部源

# Push non test NuGet packages from a build to internal organization Feed
- task: DotNetCoreCLI@2
  inputs:
    command: 'push'
    searchPatternPush: '$(Build.ArtifactStagingDirectory)/*.nupkg;!$(Build.ArtifactStagingDirectory)/*.Tests.nupkg'
    feedPublish: 'FabrikamFeed'

将 NuGet 包推送到外部源

# Push all NuGet packages from a build to external Feed
- task: DotNetCoreCLI@2
  inputs:
    command: 'push'
    nugetFeedType: 'external'
    externalEndPoint: 'MyNuGetServiceConnection'

Pack 示例

将 NuGetPackage 打包到特定的输出目录

# Pack a NuGet package to a test directory
- task: DotNetCoreCLI@2
  inputs: 
    command: 'pack'
    outputDir: '$(Build.ArtifactStagingDirectory)/TestDir'

打包符号包

# Pack a symbol package along with NuGet package
- task: DotNetCoreCLI@2
  inputs: 
    command: 'pack'
    includesymbols: true

发布示例

将项目发布到指定文件夹

# Publish projects to specified folder.
- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '**/*.csproj'
    arguments: '-o $(Build.ArtifactStagingDirectory)/Output'
    zipAfterPublish: true
    modifyOutputPath: true

还原示例

#Restore packages with the .NET Core CLI task
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: 'restore'
    feedsToUse: 'select'
    feedRestore: 'projectName/feedName'
    projects: '**/*.csproj'
    includeNuGetOrg: true

测试示例

在存储库中运行测试

# Run tests and auto publish test results.
- task: DotNetCoreCLI@2
  inputs:
    command: 'test'

要求

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