Create a NuGet package in 5 minutes

1. Register for a NuGet account to get your Access Key needed for deploying your NuGet Package to the public repository.

2. Install NuGet.

3.  Then download the NuGet.exe command-line utility.

4.  Create a .nuspec file

[sourcecode language="xml"]
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata >
<id>MarrDataMapper</id>
<version>1.0.0</version>
<authors>Jordan Marr, Rick Schott(NuGet)</authors>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Marr DataMapper provides a fast and easy to use wrapper around ADO.NET that enables you to focus more on your data access queries without having to write plumbing code.</description>
<language>en-US</language>
<projectUrl>http://marrdatamapper.codeplex.com/</projectUrl>
<licenseUrl>http://marrdatamapper.codeplex.com/license</licenseUrl>
<tags>ORM</tags>
</metadata>
<files>
<file src="binDebug*.dll" target="lib" />
</files>
</package>
[/sourcecode]

5. Pack your NuGet package from the command-line:

[sourcecode language="xml"]
NuGet.exe pack marrdatamapper.nuspec -b "path to your project"  -o "path for output of generated .nupkg file"
[/sourcecode]

I do mine in the post-build event like this so my .nupkg is always ready to be published:

[sourcecode language="xml"]
"$(ProjectDir)NuGetNuGet.exe" pack "$(ProjectDir)NuGetmarrdatamapper.nuspec" -b "$(ProjectDir)" -o "$(ProjectDir)$(OutDir)"
[/sourcecode]

6.  The last step is to push your .nupkg file to the NuGet Gallery

[sourcecode language="xml"]
nuget.exe push "..bin/debug/MarrDataMapper.1.0.0.nupkg" 99999999-9999-9999-9999-999999999999
[/sourcecode]

Results:
A fresh new package in the NuGet Gallery online and the Visual Studio Package Manager.

Resources:
NuGet.org
Package Manager Console Command Reference
Creating a Package
.nuspec File Format

3 Responses to Create a NuGet package in 5 minutes

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>