Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use dotnet pack to create a nuget package for .net core

With all dependencies added to the package.

I've tried multiple ways but it looks like I might have to get messy to do it, adding a nuspec file on its own is not sufficient because of the way in which dependencies are resolved.

To put this into perspective If I a package a .net framework project with a nuspec file and in the file point at the relevant output folder (for example bin\release) of a build I get everything I need.

My use case is to run some acceptance tests (out of process) in a CI pipeline. At this point I don't want to be accessing source control.

like image 332
brumScouse Avatar asked Apr 10 '18 07:04

brumScouse


People also ask

Can I use net framework NuGet in .NET core?

Net Framework will not be part of the . Net Standard, particularly once you get into those areas that have been most heavily refactored by . Net Core (e.g. ASP.Net). You can use this extension for visual studio to check the compatibility.


1 Answers

Take a look at NuGet.Build.Tasks.Pack

You can use a .nuspec file to pack your project if you reference at NuGet.Build.Tasks.Pack. I've done this to roll up multiple projects in my solution into one nuget package.

You can pack with dotnet.exe:

dotnet pack <path to .csproj file> /p:NuspecFile=<path to nuspec file> /p:NuspecProperties=<> /p:NuspecBasePath=<Base path>

Or MSBuild:

msbuild /t:pack <path to .csproj file> /p:NuspecFile=<path to nuspec file> /p:NuspecProperties=<> /p:NuspecBasePath=<Base path>

More details can be found here: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#packing-using-a-nuspec

like image 200
Tony Ranieri Avatar answered Sep 28 '22 10:09

Tony Ranieri