I'm creating my first Azure build pipeline for a .Net Core 2.1 solution. I've had success with DotNetCoreCLI@2
for all of my steps, that is, except for the pack step.
This works, and is currently what I have resorted to:
- script: |
dotnet pack src/MyProject/MyProject.csproj --version-suffix $(VersionSuffix) --configuration $(BuildConfiguration) --no-restore --no-build --output $(Build.ArtifactStagingDirectory)
displayName: 'dotnet pack [$(BuildConfiguration)]'
This does not work, in that it ignores the --version-suffix
directive:
- 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)]'
(I've left one of my TODOs in there as a side quest)
Also, the version prefix resides in the csproj file:
<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/>
When I use the dotnet pack
I see a NuGet package with the full version (i.e. <prefix>-<suffix>
) as I expect; e.g. 0.1.0-190813.02.abcdef
.
When I use the DotNetCoreCLI@2
task the version is limited to the version prefix; e.g. 0.1.0
.
What have I missed? Ideally I would like the pipeline yaml file to be consistent.
What have I missed? Ideally I would like the pipeline yaml file to be consistent.
No, you did not miss anything. This behavior is by designed for DotNetCoreCLI@2
.
When you check that task in the classic editor without YAML, you can see there is no such Arguments option, instead of Pack options:
So, we could use this option to define the package version.
Besides, according to the document .NET Core CLI task, the description for the arguments when you use it in YAML:
The argument -version
for Pack
is not accept, we need use the custom command, which is the method you are using now.
So, you are on the right way now, do not need to worry about it.
Hope this helps.
I also stumbled onto this problem and found out that DotNetCoreCLI is not going to help me with version suffixes per @Leo answer.
Way to overcome this problem is to pack your project with powershell
task. A simple example:
- powershell: 'dotnet pack -o $(build.artifactstagingdirectory) --no-build --no-restore -c ${{ parameters.configuration }} ${{ parameters.projectPath }}'
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With