NuGet is the package manager for the Microsoft development platform including .NET. The NuGet client tools provide the ability to produce and consume packages. The NuGet Gallery is the central package repository used by all package authors and consumers.
This post will create you how to create and publish your own NuGet package.
Let’s begin by downloading NuGet. NuGet is included in Visual Studio 2010, 2012 and 2013 extension manager. But I recommend you downloading the command line utility. I would then copy the file to
C:Windows folder to be able to use it anywhere.
Let’s now create our package.
Begin by signing up on NuGet.org and retrieving your API Key. This will be required when you want to push your package through command line. If you want, you can also upload your package on their site.
Open up command prompt, type in
nuget setApiKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxwhere the xx’s are your API Key.
Next cd into your project folder. Then type
nuget spec YourProject.csproj. That creates a .nuspec file with info about your package. If you don’t edit that file, NuGet will automatically fetch required information from your program’s AssemblyInfo.cs file.
<?xml version="1.0"?> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>$id$</id> <version>$version$</version> <authors>$author$</authors> <owners>$author$</owners> <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl> <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl> <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>$description$</description> <tags>Tag1 Tag2</tags> </metadata> </package>
nuget pack YourProject.csproj. That creates a .nupkg file with your NuGet package. It specifies the version in the filename, so it can be updated later on with newer versions.
nuget push NuGetPackageName.nupkgwhere you specify the name of your NuGet package (.nupkg in your project directory). This pushes your NuGet package to NuGet Gallery online.
You’re all done!
When you update your project, you create a new NuGet package and push it like mentioned before. NuGet will automatically update your package online.