我正在为 .Net Core 2.1 解决方案创建第一个 Azure 构建管道。我在所有步骤中都取得了成功,除了打包步骤。
这有效,并且是我目前所采用的方法:
DotNetCoreCLI@2
这不起作用,因为它忽略了
- script: |
dotnet pack src/MyProject/MyProject.csproj --version-suffix $(VersionSuffix) --configuration $(BuildConfiguration) --no-restore --no-build --output $(Build.ArtifactStagingDirectory)
displayName: 'dotnet pack [$(BuildConfiguration)]'
指令:
--version-suffix
(我把我的待办事项之一留在那里作为支线任务)
此外,版本前缀位于 csproj 文件中:
- task: DotNetCoreCLI@2
inputs:
command: 'pack'
# packagesToPack: '**/*.csproj; **/!*Test*.csproj' - TODO pack all projects, except test projects
packagesToPack: 'src/MyProject/MyProject.csproj'
arguments: '--version-suffix $(VersionSuffix) --configuration $(BuildConfiguration) --no-restore --no-build --output $(Build.ArtifactStagingDirectory)'
displayName: 'dotnet pack [$(BuildConfiguration)]'
当我使用
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>MyProject</PackageId>
<Authors>Me</Authors>
<Description>A description</Description>
<VersionPrefix>0.1.0</VersionPrefix>
<IsPackable>true</IsPackable>
</PropertyGroup>
<Project/>
时,我会看到一个包含完整版本(即
dotnet pack
)的 NuGet 包,正如我所期望的那样;例如<prefix>-<suffix>
。当我使用
0.1.0-190813.02.abcdef
任务时,版本仅限于版本前缀;例如
DotNetCoreCLI@2
。我错过了什么?理想情况下,我希望管道 yaml 文件保持一致。
解决这个问题的方法是用
Pack
任务打包你的项目。一个简单的例子:
powershell
- powershell: 'dotnet pack -o $(build.artifactstagingdirectory) --no-build --no-restore -c ${{ parameters.configuration }} ${{ parameters.projectPath }}'
```
在我的 .csproj 文件中,我的版本设置如下:
- task: PowerShell@2 #this task is due to the version argument not being possible to use in the next DotNetCoreCLI task
displayName: 'Set Version in Project File'
inputs:
targetType: 'inline'
script: |
$projectFilePath = "${{ parameters.project }}"
$version = "$(prefix)-$(suffix)" # Modify this according to your versioning scheme
(Get-Content $projectFilePath) | ForEach-Object { $_ -replace '<Version>x.x.x</Version>', "<Version>$version</Version>" } | Set-Content $projectFilePath
因此 powershell 脚本替换了版本,这导致您不必向 dotnet pack 命令提供版本
<PropertyGroup>
<Version>x.x.x</Version>
</PropertyGroup>