Part of my recent PushbulletSharp updates was getting my software to NuGet. There’s a couple of tutorials out there that will guide you through it, and I’m going to add to that list with my experience of creating the PushbulletSharp NuGet package.
Out of all of the tutorials out there, the one that helped me along the most was called 5 simple steps to publishing a NuGet package by Damien Guard. I recommend reading through this guide as it will help you get your package created and published to NuGet. Some of it is out of date now, and I’ll cover that, but for the most part it’s great.
Here’s what I did to get PushbulletSharp on NuGet:
Download the nuget.exe from NuGet.org’s Installing NuGet page. For my project I created a folder called ‘nuget’ and added it to the .gitignore file because I didn’t want to push it to GitHub. The entry is just ‘nuget/’. I placed the nuget.exe file inside that directory.
Step 2: (optional)
Refer to Step 1 of Damien’s 5 step guide. It’s about targeting multiple platforms. I skipped this step.
Create the .nuspec file.
Open a PowerShell window, browse to the folder with the nuget.exe file you downloaded in step one, and run:
This will create a XML file called Package.nuspec. This is what mine looks like for PushbulletSharp:
<?xml version="1.0"?> <package > <metadata> <id>PushBulletSharp</id> <title>PushBulletSharp</title> <version>1.2.1</version> <authors>Adam Yeager</authors> <owners>Adam Yeager</owners> <licenseUrl>http://opensource.org/licenses/MIT</licenseUrl> <projectUrl>https://github.com/adamyeager/PushbulletSharp</projectUrl> <iconUrl>http://aninternetwebsite.com/nuget/pushbulletsharp.png</iconUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>A simple C# wrapper to PushBullet's HTTP API.</description> <summary>A simple C# wrapper to PushBullet's HTTP API.</summary> <releaseNotes>Updated the Unit Tests project. Updated the setter for the 'type' property on the base class for push objects.</releaseNotes> <copyright>Copyright 2014</copyright> <tags>PushBullet PushBulletSharp</tags> </metadata> <files> <file src="..\PushBulletSharp\bin\Release\*.dll" target="lib\net45" /> <file src="..\PushBulletSharp\bin\Release\*.pdb" target="lib\net45" /> </files> </package>
The entries to pay attention to are the two file child nodes under . Because the nuget.exe is in a folder called nuget at the root of my project, I only had to go back one directory and then navigate to PushbulletSharp\bin\Release\. From there I’m getting all .dll files and .pdb files. Since I’m using .NET 4.5, I set that as my target with ‘target=”lib\net45″‘.
Creating the .nupkg file. With a PowerShell window type in:
nuget pack Package.nuspec
One of the coolest things about nuget is being able to add your own local or shared repository. This can be extremely awesome if you’re in an organization that has multiple teams needing to use internal libraries. You can setup a shared drive and configure Visual Studio to point to the shared drive as a corporate nuget repo.
To do this locally, create a test folder. I created one at ‘D:\_workarea\NugetTestRepo’.
Next I published my package to it with ‘nuget push Package.nuspec -source D:\_workarea\NugetTestRepo’.
Next in Visual Studio go to ‘Tools > NuGet Package Manager > Package Manager Settings > Package Sources’. Click the Plus sign near the top right to add your local repo. I named mine ‘Local Testing’ and the directory is ‘D:\_workarea\NugetTestRepo’.
Doing this will allow you to create a test project where you can add your nuget package and test it locally before pushing it live.
Push your package to NuGet.org. You’ll need an account there. Once you’ve registered, go to your account and copy your API key.
Using PowerShell, run the command:
nuget setApiKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Where all of the X’s is actually your Api key from your account page.
After that, you can run:
nuget push Package.nuspec
And it will push your package to NuGet!