TL;DR;
With new SDK (core) .csproj file formats, use dotnet pack
, and the DevOps pipeline task DotNetCoreCLI@2
with the pack
command option to pack libraries into NuGet packages. nuget pack
was used for the older .Net framework project formats.
Op stated
We are generating nuget packages on Azure pipelines using the the "nuget pack" task
nuget pack
is used in conjunction with the older "non-SDK" .csproj (.Net Framework) file format, and requires the addition of an additional .nuspec file placed in the same directory as the .csproj file with the same name as the project (e.g. Foo.csproj
needs Foo.nuspec
). You can then edit the authors
, version
and other package info as needed in the .nuspec file.
However, I would strongly suggest you move all your projects across to the new SDK style .csproj format, as used by .Net Core + Standard. The new project format ALSO supports .Net Framework, and has a multitude of benefits with handling of package dependencies, simplification of binding redirects, and conciseness, and removes the need for a separate .nuspec file.
Conversion of an old .csproj class library to the new format is usually as simple as
- Make a note of the project dependencies, and package dependencies in the
packages.config
file
- Delete the old .csproj file, .nuspec file (if present), the
Properties/AssemblyInfo.cs
file, and packages.config
file
- Create a new .net standard project file and copy it across to the project directory
- Edit the .csproj file (unlike the old project format, you don't need to unload it first) and change the target framework as applicable, e.g. to
<TargetFramework>net48</TargetFramework>
or whatever your .Net Framework version was.
- Better still:
- If your project isn't tied to .Net framework (e.g. if it's a library of class POCOs and Interfaces), leave it as .Net Standard. This will work on any .Net project, including Framework.
- Or, if you can try multi-targetting of your project to both .Net Framework AND core
<TargetFrameworks>net48;net5.0</TargetFrameworks>
(note the plural, TargetFrameworks). net5.0
is the same as netcoreapp5.0
- Once created, you'll be able to change the NuGet Package information for your new project assembly in the
Project Properties -> Package tab
in VS, or manually edit the .csproj file as per @C-Jarp's answer
On your Azure DevOps pipeline, after building your library, you can then pack it with the DotNetCoreCLI@2
pack task:
... restore + build steps
... unit test step
- task: DotNetCoreCLI@2
displayName: Packaging NuGets
inputs:
command: 'pack'
arguments: '--configuration $(buildConfiguration)'
packagesToPack: |
MyLibrary/MyLibrary.csproj;
.. Other libraries;
And now you can push it to your NuGet repository (e.g. DevOps artifacts)