0

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 ?

Sam
  • 13,934
  • 26
  • 108
  • 194
  • Can you set `packagesToPack` to your csproj, and use `buildProperties: 'PackageID=CustomPrefix.$(ProjectName)'`? – ESG Jul 08 '20 at 16:01
  • but there are more than one project in the solution. And $(ProjectName) has no meaning here, only when running locally. Unless the task knows how to replace this by each project's name in the solution ? – Sam Jul 08 '20 at 16:22

2 Answers2

1

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
ESG
  • 8,988
  • 3
  • 35
  • 52
  • Ok, I'll mark this as the answer. However I do not want to have PackageId in all my csproj, I find this to be a pain. Since I had no idea how to workaround this, I ended up writing my own powershell script to iterate through all projects in solution and calling dotnet pack with the proper arguments. Thanks anyway, it's useful ! – Sam Jul 08 '20 at 19:11
  • You could include a props file in all your csproj, but it also requires modifying all of them unfortunately. – ESG Jul 08 '20 at 19:40
  • true. Actually I did give it a try because with my powershell I was running into another issue. With your method, I ran into the very same issue, which is described here : https://stackoverflow.com/questions/62803055/how-to-override-nuget-dependencies-id-in-nuspec-file – Sam Jul 08 '20 at 20:23
-2

Please, take a look more in packagesToPack: '${{parameters.solutionPath}}' In my experience we usually write these commands just with one "{ }" Try to do it: packagesToPack: '${parameters.solutionPath}' to see if it can solve.