DotNetCoreCLI@2 - .NET Core v2 工作

建置、測試、封裝或發佈 dotnet 應用程式,或執行自定義 dotnet 命令。

建置、測試、封裝或發佈 dotnet 應用程式,或執行自定義 dotnet 命令。 對於套件命令,支援 NuGet.org 和已驗證的摘要,例如套件管理和 MyGet。

重要

NuGet 驗證工作是使用 Azure Artifacts 和其他 NuGet 存放庫進行驗證的新建議方式。 restore此 .NET Core CLI 工作的 和 push 命令不再採用新功能,而且只會解決重大錯誤。 如需詳細資訊,請參閱備註。

Syntax

# .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 推送) 、pack、、restorepublish、、、runtestcustom。 預設值:build

要執行的 dotnet 命令。 指定 custom 以新增自變數或使用此處未列出的命令。

重要

NuGet 驗證工作是使用 Azure Artifacts 和其他 NuGet 存放庫進行驗證的新建議方式。 restore此 .NET Core CLI 工作的 和 push 命令不再採用新功能,而且只會解決重大錯誤。 如需詳細資訊,請參閱備註。


publishWebProjects - 發佈 Web 專案
boolean. 選擇性。 使用時機 command = publish。 預設值:true

如果此輸入設定 true為 , projects 則會略過 屬性值,而工作會嘗試在存放庫中尋找 Web 專案,並在其上執行 publish 命令。 Web 專案是由目錄中的 web.config 檔案或 wwwroot 資料夾存在來識別。 如果沒有 web.config 檔案或 wwwroot 資料夾,則會選擇使用 Web SDK 的專案, 例如 Microsoft.NET.Sdk.Web


publishWebProjects - 發佈 Web 專案
boolean. 選擇性。 使用時機 command = publish。 預設值:true

如果此輸入設定 true為 , projects 則會略過 屬性值,而工作會嘗試在存放庫中尋找 Web 專案,並在其上執行 publish 命令。 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

要使用的 或 .sln 檔案路徑 .csproj () 。 您可以使用通配符 (,例如 **/*.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

指定所選命令的自變數。 例如,建置組態、輸出資料夾和運行時間。 自變數取決於選取的命令。

此輸入目前只接受、publishruntestcustombuild自變數。 如果您要為未列出的指令新增自變數,請使用 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 - Zip 已發佈的專案
boolean. 選擇性。 使用時機 command = publish。 預設值:true

如果此輸入設定為 true,則發行命令所建立的資料夾將會壓縮並刪除。


zipAfterPublish - Zip 已發佈的專案
boolean. 選擇性。 使用時機 command = publish。 預設值:true

如果此輸入設定為 true,則 publish 命令所建立的資料夾將會壓縮並刪除。


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。 允許的值:-、、、MinimalQuietNormalDetailed、、 Diagnostic。 預設值:Detailed

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


packagesToPush - 要發行的 NuGet 套件路徑 (s)
輸入別名: 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.Y.ZX 版中的 。


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

X.Y.ZY 版中的 。


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

X.Y.ZZ 版中的 。


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

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


verbosityPack - 冗長
string. 選擇性。 使用時機 command = pack。 允許的值:-、、、QuietMinimalNormalDetailedDiagnostic 預設值: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 命令不再採用新功能,而且只會解決重大錯誤。

為什麼我的組建、發佈或測試步驟無法還原套件?

大部分 dotnet 的命令,包括 buildpublishtest 包含隱含 restore 步驟。 即使您在先前的步驟中成功 dotnet restore 執行,這也會針對已驗證的摘要失敗,因為先前的步驟將會清除所使用的認證。

若要修正此問題,請將 --no-restore 旗標新增至 Arguments 文本框。

此外,test命令無法辨識 feedRestorevstsFeed 自變數,而且隱含restore步驟執行時,以這種方式指定的摘要將不會包含在產生的NuGet.config檔案中。 建議您使用明確的 dotnet restore 步驟來還原套件。 restore命令會feedRestore遵守和 vstsFeed 自變數。

為什麼我在機器上建置時收到套件 來源對應的 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 入原始檔控制可確保建置專案所需的主要資訊片段,也就是其套件的位置,可供每個簽出程式代碼的開發人員使用。

不過,對於開發人員小組在大量專案上工作的情況,您也可以將 Azure Artifacts 摘要新增至每個開發人員計算機上的全域 NuGet.config 。 在這些情況下,使用 Feeds I select here NuGet 工作中的選項會復寫此設定。

疑難排解

使用 Entity Framework 的專案已停止在託管代理程式上運作

.NET Core 沒有 Entity Framework (EF) 內建。 您必須先安裝EF,才能開始執行,或新增 global.json 至具有必要 .NET Core SDK 版本的專案。 這可確保使用正確的 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'

套件範例

將 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、傳統組建、傳統版本
在上執行 代理程式
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任何
可設定變數 任何
代理程式版本 2.144.0 或更新版本
工作類別 建置
需求 描述
管線類型 YAML、傳統組建、傳統版本
在上執行 代理程式
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任何
可設定變數 任何
代理程式版本 2.115.0 或更新版本
工作類別 建置
需求 描述
管線類型 YAML、傳統組建、傳統版本
在上執行 代理程式
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任何
可設定變數 任何
代理程式版本 2.0.0 或更新版本
工作類別 建置