Skip to content

Instantly share code, notes, and snippets.

@andykuszyk
Last active July 8, 2021 14:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andykuszyk/a5ee80ae263e77f651bed878c1deb03b to your computer and use it in GitHub Desktop.
Save andykuszyk/a5ee80ae263e77f651bed878c1deb03b 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]

@ardalis
Copy link

ardalis commented Apr 30, 2021

The nuget push at the end doesn't work; need to change -s to -src or -source.

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