Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DotNetCoreCLI@2 pack task ignores version suffix directive

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.

like image 310
Jevon Kendon Avatar asked Aug 13 '19 09:08

Jevon Kendon


2 Answers

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:

enter image description here

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:

enter image description here

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.

like image 97
Leo Liu-MSFT Avatar answered Nov 15 '22 08:11

Leo Liu-MSFT


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 }}'
    ```
like image 35
Shoter Avatar answered Nov 15 '22 08:11

Shoter