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).
#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. Feeds to use. Default: select.
#vstsFeed: # string. Alias: feedRestore. Optional. Use when selectOrConfig = select. Use packages from this Azure Artifacts feed.
#includeNuGetOrg: true # boolean. Optional. Use when selectOrConfig = select. Use packages from NuGet.org. Default: true.
#nugetConfigPath: # string. Optional. Use when selectOrConfig = config. Path to NuGet.config.
#externalFeedCredentials: # string. Alias: externalEndpoints. Optional. Use when selectOrConfig = config. Credentials for feeds outside this organization/collection.
# Advanced
#noCache: false # boolean. Disable local cache. Default: false.
#restoreDirectory: # string. Alias: packagesDirectory. Destination directory.
#verbosityRestore: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Verbosity. Default: Detailed.
# Advanced
#publishPackageMetadata: true # boolean. Optional. Use when command = push && nuGetFeedType = internal. Publish pipeline metadata. Default: true.
# Pack options
versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required. Automatic package versioning. Default: off.
#versionEnvVar: # string. Required when versioningScheme = byEnvVar. Environment variable.
#majorVersion: '1' # string. Alias: requestedMajorVersion. Required when versioningScheme = byPrereleaseNumber. Major. Default: 1.
#minorVersion: '0' # string. Alias: requestedMinorVersion. Required when versioningScheme = byPrereleaseNumber. Minor. Default: 0.
#patchVersion: '0' # string. Alias: requestedPatchVersion. Required when versioningScheme = byPrereleaseNumber. Patch. Default: 0.
# Advanced
#buildProperties: # string. Additional build properties.
#verbosityPack: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Verbosity. Default: Detailed.
# Advanced
#workingDirectory: # string. Optional. Use when command != restore && command != push && command != pack. 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. Feeds to use. Default: select.
#vstsFeed: # string. Alias: feedRestore. Optional. Use when selectOrConfig = select. Use packages from this Azure Artifacts feed.
#includeNuGetOrg: true # boolean. Optional. Use when selectOrConfig = select. Use packages from NuGet.org. Default: true.
#nugetConfigPath: # string. Optional. Use when selectOrConfig = config. Path to NuGet.config.
#externalFeedCredentials: # string. Alias: externalEndpoints. Optional. Use when selectOrConfig = config. Credentials for feeds outside this organization/collection.
# Advanced
#noCache: false # boolean. Disable local cache. Default: false.
#restoreDirectory: # string. Alias: packagesDirectory. Destination directory.
#verbosityRestore: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Verbosity. Default: Detailed.
# Advanced
#publishPackageMetadata: true # boolean. Optional. Use when command = push && nuGetFeedType = internal. Publish pipeline metadata. Default: true.
# Pack options
versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required. Automatic package versioning. Default: off.
#versionEnvVar: # string. Required when versioningScheme = byEnvVar. Environment variable.
#majorVersion: '1' # string. Alias: requestedMajorVersion. Required when versioningScheme = byPrereleaseNumber. Major. Default: 1.
#minorVersion: '0' # string. Alias: requestedMinorVersion. Required when versioningScheme = byPrereleaseNumber. Minor. Default: 0.
#patchVersion: '0' # string. Alias: requestedPatchVersion. Required when versioningScheme = byPrereleaseNumber. Patch. Default: 0.
# Advanced
#buildProperties: # string. Additional build properties.
#verbosityPack: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Verbosity. Default: Detailed.
# Advanced
#workingDirectory: # string. 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. Feeds to use. Default: select.
#vstsFeed: # string. Alias: feedRestore. Optional. Use when selectOrConfig = select. Use packages from this Azure Artifacts/TFS feed.
#includeNuGetOrg: true # boolean. Optional. Use when selectOrConfig = select. Use packages from NuGet.org. Default: true.
#nugetConfigPath: # string. Optional. Use when selectOrConfig = config. Path to NuGet.config.
#externalFeedCredentials: # string. Alias: externalEndpoints. Optional. Use when selectOrConfig = config. Credentials for feeds outside this organization/collection.
# Advanced
#noCache: false # boolean. Disable local cache. Default: false.
#restoreDirectory: # string. Alias: packagesDirectory. Destination directory.
#verbosityRestore: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Verbosity. Default: Detailed.
# Pack options
versioningScheme: 'off' # 'off' | 'byPrereleaseNumber' | 'byEnvVar' | 'byBuildNumber'. Required. Automatic package versioning. Default: off.
#versionEnvVar: # string. Required when versioningScheme = byEnvVar. Environment variable.
#majorVersion: '1' # string. Alias: requestedMajorVersion. Required when versioningScheme = byPrereleaseNumber. Major. Default: 1.
#minorVersion: '0' # string. Alias: requestedMinorVersion. Required when versioningScheme = byPrereleaseNumber. Minor. Default: 0.
#patchVersion: '0' # string. Alias: requestedPatchVersion. Required when versioningScheme = byPrereleaseNumber. Patch. Default: 0.
# Advanced
#buildProperties: # string. Additional build properties.
#verbosityPack: 'Detailed' # '-' | 'Quiet' | 'Minimal' | 'Normal' | 'Detailed' | 'Diagnostic'. Verbosity. Default: Detailed.
# Advanced
#workingDirectory: # string. Working Directory.
# YAML Syntax is not supported in TFS 2018.
# Use the classic designer to add and configure tasks.
# See the following Inputs section for details on the inputs that this task supports.
輸入
command
- 命令
string
. 必要。 允許的值: build
、 (nuget 推送) 、 pack
、、 publish
、 restore
、 run
、、 test
custom
。 push
預設值: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
。
要使用的檔案路徑 .csproj
(s) 。 您可以使用萬用字元 (,例如 **/*.csproj
所有子資料夾中的所有 .csproj
檔案) 。 如需詳細資訊,請參閱 檔案比對模式參考。
arguments
- 參數
string
. 選擇性。 使用 時 command = build || command = publish || command = run || command = test || command = custom
。
指定所選命令的引數。 例如,建置組態、輸出檔案夾和執行時間。 引數取決於選取的命令。
此輸入目前只接受 、 publish
、 run
test
和 custom
的引數 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”
至命令列引數,以收集程式碼涵蓋範圍。
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
為 ,則發行命令所建立的資料夾將會壓縮並刪除。
modifyOutputPath
- 新增專案的資料夾名稱以發佈路徑
boolean
. 選擇性。 使用 時 command = publish
。 預設值:true
。
如果此輸入設定 true
為 ,當輸出路徑在引數中明確指定時,publish 命令所建立的資料夾會有前置詞為其資料夾名稱的專案檔名稱。 如果您想要將多個專案發佈至相同的資料夾,這會很有用。
modifyOutputPath
- 新增專案名稱以發佈路徑
boolean
. 選擇性。 使用 時 command = publish
。 預設值:true
。
如果此輸入設定 true
為 ,當輸出路徑在引數中明確指定時,publish 命令所建立的資料夾會有前置詞為其資料夾名稱的專案檔名稱。 如果您想要將多個專案發佈至相同的資料夾,這會很有用。
feedsToUse
- 要使用的摘要
輸入別名: selectOrConfig
。 string
. 必要。 允許的值: select
(摘要 () 我在此選取) , config
(NuGet.config) 中的摘要。 預設值:select
。
您可以從 Azure Artifacts 和/或 NuGet.org
這裡選取摘要,也可以將檔案認可 nuget.config
至原始程式碼存放庫,並使用 nugetConfigPath
輸入設定其路徑。
vstsFeed
- 使用此 Azure Artifacts 摘要中的套件
輸入別名: feedRestore
。 string
. 選擇性。 使用 時機 selectOrConfig = select
。
在產生的 NuGet.config
中包含選取的摘要。 您必須安裝套件管理並取得授權,才能在這裡選取摘要。 projectName
/feedName
用於專案範圍的摘要。 僅適用于 FeedName
組織範圍的摘要。 注意:測試命令不支援此動作。
vstsFeed
- 使用此 Azure Artifacts/TFS 摘要中的套件
輸入別名: feedRestore
。 string
. 選擇性。 使用 時機 selectOrConfig = select
。
在產生的 NuGet.config
中包含選取的摘要。 您必須安裝套件管理並取得授權,才能在這裡選取摘要。 projectName
/feedName
用於專案範圍的摘要。 僅適用于 FeedName
組織範圍的摘要。 注意:測試命令不支援此動作。
vstsFeed
- 使用此 VSTS/TFS 摘要中的套件
輸入別名: feedRestore
。 string
. 選擇性。 使用 時機 selectOrConfig = select
。
在產生的 NuGet.config
中包含選取的摘要。 您必須安裝套件管理並取得授權,才能在這裡選取摘要。
includeNuGetOrg
- 使用來自 NuGet.org 的套件
boolean
. 選擇性。 使用 時機 selectOrConfig = select
。 預設值:true
。
包含在 NuGet.org
產生的 NuGet.config
中。
nugetConfigPath
- NuGet.config的路徑
string
. 選擇性。 使用 時機 selectOrConfig = config
。
存放 NuGet.config
庫中的 ,指定要從中還原封裝的摘要。
externalFeedCredentials
- 此組織/集合外部摘要的認證
輸入別名: externalEndpoints
。 string
. 選擇性。 使用 時機 selectOrConfig = config
。
要用於所選 NuGet.config
之外部登錄的認證。 對於此組織/集合中的摘要,請將此輸入保留空白;會自動使用組建的認證。
externalFeedCredentials
- 此帳戶/集合外部摘要的認證
輸入別名: externalEndpoints
。 string
. 選擇性。 使用 時機 selectOrConfig = config
。
要用於所選 NuGet.config
之外部登錄的認證。 對於此組織/集合中的摘要,請將此輸入保留空白;會自動使用組建的認證。
noCache
- 停用本機快取
boolean
. 預設值:false
。
防止 NuGet 使用來自本機電腦快取的套件。
restoreDirectory
- 目的地目錄
輸入別名: packagesDirectory
。 string
.
指定安裝封裝的資料夾。 如果未指定任何資料夾,則會將套件還原到預設的 NuGet 套件快取。
verbosityRestore
- 冗長
string
. 允許的值: -
、、 Quiet
、 Minimal
Normal
、 Detailed
、 Diagnostic
。 預設值:Detailed
。
指定命令輸出 restore
中顯示的詳細資料量。
packagesToPush
- 要發行的 NuGet 套件 () 路徑
輸入別名: searchPatternPush
。 string
. 當 時為 必要 command = push
專案。 預設值:$(Build.ArtifactStagingDirectory)/*.nupkg
。
要比對的模式,或要上傳之 nupkg
檔案的路徑。 多個模式可以以分號分隔,而且您可以在其前面 !
加上 來建立模式負數。 範例: **/*.nupkg;!**/*.Tests.nupkg
.
nuGetFeedType
- 目標摘要位置
string
. 當 時為 必要 command = push
專案。 允許的值: internal
(此組織/集合) , external
(外部 NuGet 伺服器 (包括其他組織/集合) ) 。 預設值:internal
。
指定目標摘要為內部或外部。
nuGetFeedType
- 目標摘要位置
string
. 當 時為 必要 command = push
專案。 允許的值: internal
(此帳戶/集合) , external
(外部 NuGet 伺服器 (包括其他帳戶/集合) ) 。 預設值:internal
。
指定目標摘要為內部或外部。
publishVstsFeed
- 目標摘要
輸入別名: feedPublish
。 string
. 當 時為 必要 command = push && nuGetFeedType = internal
專案。
指定裝載在此組織中的摘要。 您必須安裝套件管理並取得授權,才能在這裡選取摘要。
publishPackageMetadata
- 發佈管線中繼資料
boolean
. 選擇性。 使用 時機 command = push && nuGetFeedType = internal
。 預設值:true
。
讓此組建/發行管線的中繼資料 (執行 #、原始程式碼資訊) 與套件產生關聯。
publishFeedCredentials
- NuGet 伺服器
輸入別名: externalEndpoint
。 string
. 當 時為 必要 command = push && nuGetFeedType = external
專案。
包含外部 NuGet 伺服器認證的 NuGet 服務連線 。
packagesToPack
- 要封裝的 csproj 或 nuspec 檔案 () 路徑
輸入別名: searchPatternPack
。 string
. 當 時為 必要 command = pack
專案。 預設值:**/*.csproj
。
要搜尋 .csproj
的模式或 .nuspec
要封裝的檔案。
您可以使用分號分隔多個模式,並以 作為前置詞 !
,使模式為負值。 範例: **/*.csproj;!**/*.Tests.csproj
.
configuration
- 組態至封裝
輸入別名: configurationToPack
。 string
. 選擇性。 使用 時機 command = pack
。 預設值:$(BuildConfiguration)
。
使用 .csproj
檔案時,此輸入會指定要封裝的組態。
packDirectory
- 封裝資料夾
輸入別名: outputDir
。 string
. 選擇性。 使用 時機 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
. 必要。 允許的值: off
、 byPrereleaseNumber
(使用日期和時間) , byEnvVar
(使用環境變數) , byBuildNumber
(使用組建編號) 。 預設值:off
。
此工作無法與內含的參考專案搭配使用。 如果您選擇 Use the date and time
,這會產生符合 SemVer規範的版本,其格式為 X.Y.Z-ci-datetime
您選擇的 X
、 Y
和 Z
。
如果您選擇 Use an environment variable
,您必須選取環境變數,並確定它包含您想要使用的版本號碼。
如果您選擇 Use the build number
,這會使用組建編號來設定套件的版本。 注意: 在 底下 Options
,將組建編號格式設定為 $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
。
versionEnvVar
- 環境變數
string
. 當 時為 必要 versioningScheme = byEnvVar
專案。
指定不含 $
、 $env
或 的 %
變數名稱。
majorVersion
- 主要
輸入別名: requestedMajorVersion
。 string
. 當 時為 必要 versioningScheme = byPrereleaseNumber
專案。 預設值:1
。
X.Y.ZX
版中的 。
minorVersion
- 小
輸入別名: requestedMinorVersion
。 string
. 當 時為 必要 versioningScheme = byPrereleaseNumber
專案。 預設值:0
。
X.Y.ZY
版中的 。
patchVersion
- 補丁
輸入別名: requestedPatchVersion
。 string
. 當 時為 必要 versioningScheme = byPrereleaseNumber
專案。 預設值:0
。
X.Y.ZZ
版中的 。
buildProperties
- 其他建置屬性
string
.
指定以分號分隔的 token = value
配對清單,其中檔案中的每個 .nuspec
出現 $token$
專案都會取代為指定的值。 值可以是引號中的字串。
verbosityPack
- 冗長
string
. 允許的值: -
、、 Quiet
、 Minimal
Normal
、 Detailed
、 Diagnostic
。 預設值:Detailed
。
指定命令輸出 pack
中顯示的詳細資料量。
workingDirectory
- 工作目錄
string
. 選擇性。 使用 時機 command != restore && command != push && command != pack
。
執行腳本的目前工作目錄。 Empty
是存放庫 (組建) 或成品 (發行) 的根目錄,也就是 $(System.DefaultWorkingDirectory)
。
workingDirectory
- 工作目錄
string
.
執行腳本的目前工作目錄。 Empty
是存放庫 (組建) 或成品 (發行) 的根目錄,也就是 $(System.DefaultWorkingDirectory)
。
工作控制選項
除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制項選項和一般工作屬性。
輸出變數
無。
備註
重要
NuGet 驗證工作是使用 Azure Artifacts 和其他 NuGet 存放庫進行驗證的新建議方式。 restore
此 .NET Core CLI 工作的 和 push
命令不再採用新功能,而且只會解決重大錯誤。
為什麼我的組建、發佈或測試步驟無法還原套件?
大部分 dotnet
的命令,包括 build
、 publish
和 test
包含隱含 restore
步驟。 即使您在先前的步驟中成功 dotnet restore
執行,這也會針對已驗證的摘要失敗,因為先前的步驟將會清除所使用的認證。
若要修正此問題,請將 --no-restore
旗標新增至 Arguments
文字方塊。
此外, test
命令無法辨識 feedRestore
或 vstsFeed
引數,而且隱含 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 或更新版本 |
工作類別 | 組建 |