Nuspec dependencies necessary with PackageReferences

498 views Asked by At

imagine the following situation:

Project A has some NuGet dependencies (ie Project Z, Project Y and Project X). It uses PackageReferences.

Now I want to pack Project A as a .nupkg using a .nuspec file. In a .nuspec file you can declare other NuGet dependencies and they will automatically resolved upon installation.

But is that necessary? I thought the PackageReferences would already resolve them.

1

There are 1 answers

0
Martin Ullrich On BEST ANSWER

When you use PackageReference items in your project, you no longer need a .nuspec file to pack a project. You should be able to pack it with dotnet pack -c Release or msbuild.exe -t:Pack -p:Configuration=Release. (Depending on the project type, you may need to install the NuGet.Build.Tasks.Pack for non-SDK-based .NET Framework projects. .NET Standard, Core, .NET 5+ projects should not need this)

You can still use a .nuspec file though, by specifying a NuspecFile property inside the csproj to instruct the pack task to use it. However, it will override all the settings that NuGet would autogenerate - that's the tradeoff for getting complete control over the .nuspec.

If you pack a project using PackageReference you can have a look at the generated .nuspec file in e.g. obj\Release\FooLib.1.0.0.nuspec.