Search code examples
.net-corenugetazure-pipelinesnuget-packagedotnet-cli

Azure Pipeline Pack Nuget Packages with custom name


In my solution I have a few projects, which pack their own nuget packages on build. When packing the package I use the PackageID parameter to add a customprefix to the package name (which otherwise would be the name of the project).

dotnet pack  .\$(ProjectName).csproj  --include-symbols --no-build -o C:\dev\Packages -p:PackageID=CustomPrefix.$(ProjectName)

It works fine.

Now, in my Azure Devop Pipeline, I was using the dotnet task to pack my packages like so:

- task: DotNetCoreCLI@2
  displayName: 'dotnet pack'
  inputs:
    command: 'pack'
    packagesToPack: '${{parameters.solutionPath}}'
    nobuild: true
    includesymbols: true
    versioningScheme: 'off'

Now obviously this does not add the prefix and I have no idea how to do it, especially since here I path the path to the actual solution, not the project. It just pack the packages for all projects in the solution, without any means to customize it. Any clue on how I could do that ?


Solution

  • You can use the MSBuildProjectName variable to reference the name of the project being built, but it doesn't work when trying to pass it via the command line.

    If you can modify the csproj files in your project, I'd recommend the adding the following under a PropertyGroup:

    <PackageIdPrefix></<PackageIdPrefix>
    <PackageId>$(PackageIdPrefix)$(MSBuildProjectName)</PackageId>
    

    Then update your pipeline to

    - task: DotNetCoreCLI@2
      displayName: 'dotnet pack'
      inputs:
        command: 'pack'
        packagesToPack: '${{parameters.solutionPath}}'
        nobuild: true
        includesymbols: true
        versioningScheme: 'off'
        buildProperties: 'PackageIdPrefix=CustomPrefix.' # <-- This is new