JustAnotherDave
JustAnotherDave

Reputation: 21

Azure DevOps "NuGet pack" task ignores/overwrites package metadata

I have setup a simple CI pipeline in Azure DevOps for building a .NET5 NuGet package, which looks like this

The pipeline is able to successfully pack and release the project as intended, but when I go to inspect the NuGet package, I find that all of the package metadata is missing (except for the version, which is correct, and the author(s), which is incorrectly showing the name of the ADO build agent as the author). I currently have all of the package metadata located in the .csproj file.

A screenshot showing the incorrect metadata, which is also what is shown when I look at the .nuspec in the NuGet package that is generated by the pipeline. Of course, when I pack the project on my local machine, all of the metadata generates the way it should.

Here

I've seen one other post similar to this where the author switched the pipeline to use dotnet tasks instead of MSBuild tasks. Unfortunately, this is not an option for me, as this project has COM references that are not supported by the dotnet CLI, so MSBuild is my only option.

Does anyone know why the 'NuGet pack' task in my pipeline is not using the metadata in my .csproj file?

Upvotes: 1

Views: 599

Answers (2)

JustAnotherDave
JustAnotherDave

Reputation: 21

The solution to this problem ended up being somewhat simple. The 'NuGet pack' task uses the nuget.exe CLI, which ignores metadata defined in the .csproj file. You have to create a .nuspec file, put all of your metadata in it, and add that file to the same directory that the .csproj file resides. As soon as I did this, my NuGet package was generated with the correct metadata.

Upvotes: 1

Leo Liu
Leo Liu

Reputation: 76670

Does anyone know why the 'NuGet pack' task in my pipeline is not using the metadata in my .csproj file?

According to the document Create a NuGet package using MSBuild:

The command that creates a package, msbuild -t:pack, is functionally equivalent to dotnet pack.

enter image description here

enter image description here

Or you could add below argument in the .csproj file, which will create the package when you build the project with VS build task:

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

Upvotes: 0

Related Questions