Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save modulexcite/3970a2e31354a4dd03933b60d1185b6a to your computer and use it in GitHub Desktop.
Save modulexcite/3970a2e31354a4dd03933b60d1185b6a to your computer and use it in GitHub Desktop.
Creating and Publishing NuGet Packages

Creating and Publishing NuGet Packages

Introduction

This document describes how to publish a nuget packages by creating a nuspec and then publishing it to a server.

How do we get from dll to publish nuget package?

In order to publish dlls as a nuget package, we need to perform these three steps:

  1. Create a nuspec;
  2. Pack the nuspec;
  3. Push the nuspec.

Create a 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

Packing the nuspec

Once you've authored the nuspec, creating the nuget package is easy with the nuget command line:

nuget pack path\to\mynuspec.nuspec

Pushing the nuget package

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment