DotNetCoreCLI@2 包任务忽略版本后缀指令

问题描述 投票:0回答:4

我正在为 .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 文件保持一致。

build azure-devops
4个回答
7
投票
我错过了什么?理想情况下,我希望管道 yaml 文件保持一致。

不,你没有错过任何事情。此行为是为
0.1.0

设计的。


当您在没有 YAML 的经典编辑器中检查该任务时,您可以看到没有这样的

Arguments

选项,而不是 Pack options:

因此,我们可以使用此选项来定义包版本。

此外

,根据文档.NET Core CLI任务,在YAML中使用时参数的说明:

DotNetCoreCLI@2的参数

-version
不被接受
,我们需要使用自定义命令,这就是您现在使用的方法。
所以,你现在走在正确的道路上,不需要担心。

希望这有帮助。


6
投票

解决这个问题的方法是用

Pack

任务打包你的项目。一个简单的例子:

powershell



0
投票

- 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 命令提供版本


-1
投票

<PropertyGroup> <Version>x.x.x</Version> </PropertyGroup>

© www.soinside.com 2019 - 2024. All rights reserved.