This document describes how to publish a nuget packages by creating a nuspec and then publishing it to a server.
In order to publish dlls as a nuget package, we need to perform these three steps:
- Create a nuspec;
- Pack the nuspec;
- Push the nuspec.
A nuspec is an xml file that describes what goes into a nuget package (i.e. where the dlls live) as well as some metadata such as the author, version and any nuget package dependecies.
A nuspec file can be created using the nuget command line using:
nuget spec
Alternatively, this template can be used:
<?xml version="1.0"?>
<package >
<metadata>
<id>[Name of nuget package]</id>
<version>[Version of nuget package]</version>
<authors></authors>
<owners></owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>[Description of nuget package]</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2016</copyright>
<tags></tags>
<dependencies>
<dependency id="[Name of dependant nuget package]" version="[Version of dependant nuget package]" />
</dependencies>
</metadata>
<files>
<file src="[Path to dll or file to include]" target="[Destination directory inside nuget package]"/>
</files>
</package>
- The id and version uniquely identify the nuget package.
- Dependencies are note required, but its best practice to specify them rather than including the dependant dlls in your package.
- Files are used to specify the individual files you want to include. The target typically indicates the .NET version the dlls were built in, e.g. lib/net45
Once you've authored the nuspec, creating the nuget package is easy with the nuget command line:
nuget pack path\to\mynuspec.nuspec
Once the nuget package has been built, it can be pushed directly to our nuget server using:
nuget push path\to\mynuget.nupkg -s [serveraddress] [securitytoken]
The nuget push at the end doesn't work; need to change -s to -src or -source.