Package version is always 1.0.0 with dotnet pack

后端 未结 3 1569
小鲜肉
小鲜肉 2021-02-02 05:31

TLDR: Where is dotnet pack pulling the version information when it creates the nuget package for an assembly?

I have a library, that I had transitioned fr

相关标签:
3条回答
  • 2021-02-02 05:55

    When you use dotnet pack, the version is pulled from the project definition (previously project.json, now *.csproj), not AssemblyInfo.cs. So, your new workflow will be very similar to what it was with project.json.

    From the project.json to csproj migration docs, you can use the VersionPrefix and VersionSuffix properties.

    Before:

    {
      "version": "1.0.0-alpha-*"
    }
    

    Now:

    <PropertyGroup>
      <VersionPrefix>1.0.0</VersionPrefix>
      <VersionSuffix>alpha</VersionSuffix>
    </PropertyGroup>
    

    You can also use the single Version property, but the docs warn that this "may override version settings during packaging".

    <PropertyGroup>
      <Version>1.0.0-alpha</Version>
    </PropertyGroup>
    
    0 讨论(0)
  • 2021-02-02 06:01

    NOTE: I understand this question is not specifically about VSTS/Azure Dev Ops but a search for how to do this on a build pipeline lands here so adding what worked for me

    1. Use the dotnet core task
    2. Tools version 2.*
    3. Command = custom
    4. Custom Command = pack
    5. Arguments = -p:Version=1.0.$(Build.BuildId) -o $(Build.ArtifactStagingDirectory)

    The -o argument is required if the task following the packaging is going to push to a feed (isn't that why one would build packages?)

    0 讨论(0)
  • 2021-02-02 06:11

    Better yet, specify /p:Version=$(Build.BuildNumber) (TFS/VSTS) on the dotnet pack command and it will build it with the specified version in the nuget package. Example (non TFS specific):

    dotnet pack .\src\example\example.csproj -o c:\published\example -c Release /p:Version=1.2.3
    

    Example (TFS specific) <- we use this for our TFS 2017 packing using a powershell script step.

    dotnet pack $(Build.SourcesDirectory)\src\example\example.csproj -o $(Build.ArtifactStagingDirectory)\Pack -c Release /p:Version=$(Build.BuildNumber)
    

    Note: It does not update package reference versions.

    0 讨论(0)
提交回复
热议问题