How to create a NuGet package from a .NET Core class library

I’ve built a few class libraries recently but in order to use them in other projects they need to be created as a NuGet package and uploaded. The easiest way to creat the NuGet package is to add a script section to the projects project.json file telling it to create a NuGet package after it’s built.

"scripts": {
	"postcompile": [
		"dotnet pack --no-build --configuration %compile:Configuration%"
	]
}

To pre-populate a couple of the fields in the in NuGet when the package is uploaded the assembly information in the application tab of the project properties should be filled in. Project versioning is also controlled from here.

The package will then be created in the Debug or Release folder of the project depending on which is selected in the project.

In Visual Studio 2017 NuGet package creation is much easier as there is now a “Generate NuGet package on build” option in the Package tab of the project properties.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *