Search code examples
c#nugetgitversion

Using C#, GitVersion.MsBuild and dotnet pack, how can I put a suffix in my NuGet name like "MyProject-1.0.0--staging.nupkg"?


I am generating a NuGet package from a C# project. I want to be able to set suffixes on my NuGet package names, such as MyProject-1.0.0--staging and MyProject-1.0.0--development.

Merely renaming the .nupkg file is not enough, because the name is apparently baked into it.

I have tried to set the --version-suffix argument to dotnet pack, but this value gets ignored. This is possibly because I am also using GitVersion. My dotnet pack command looks like this:

dotnet pack . \
    -c:Release \
    --no-build \
    --no-restore \
    -p:UseGitVersion=true \
    -p:CIBuild=true \
    -p:PackageOutputPath='${{ github.workspace }}/${{ env.nugetPackOutputDir }}' \
    -v:minimal \
    --version-suffix '-${{ env.environment }}'

I have read that --version-suffix gets ignored if my CSPROJ file contains a tag. I do not have such a tag, but perhaps GitVersion generates one at compile-time.

My CSPROJ contains this:

    <PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

How can I set a suffix on my NuGet package name - either with a parameter to dotnet pack or in my GitVersion.yml or elsewhere?

I can see that the GitVersion variables contain a variable called PreReleaseLabel, but I cannot find out whether and how I can set the value of this variable.


Solution

  • I turns out that I can set the suffix by putting this in my GitVersion.yml:

    branches:
      feature:
        source-branches: [ 'master' ]
        tag: '{BranchName}developmentsuffix'
      master:
        tag: 'mastersuffix'