Creating Your Own NuGet Package, Part 2

Automagically Using NuGet with a Project

Want to automate things even more?

For this example, find a Class Library project that you like.  Open a command prompt and navigate to the folder where the .csproj file for that project is.

nuget spec

Bam. Now you have a .nuspec file created automatigically.  You’ll notice some strings that look like some kind of replacement tokens:  $abc$.  We’ll get to these in a minute. They’re pretty awesome.  To make full use of this next step, though, we’ll want to a few quick things first:

  1. Open the .nuspec file that was created.
    1. Change or remove:
      1. <licenseUrl>
      2. <projectUrl>
      3. <iconUrl>
    2. Change <releaseNotes> to whatever you would like (having nothing here is fine too).
    3. Change <tags> to whatever you would like (having nothing here is fine too).
  2. Open your project’s AssemblyInfo.cs file, and enter some values for:
    1. AssemblyTitle
    2. AssemblyDescription
    3. AssemblyVersion

Are you ready for something really cool?  Go back to your command line (in the same folder where .csproj is):

nuget pack

Check out your package in NuGet (using whatever Package Source you use to host it).  All of the metadata from AssemblyInfo.cs is automagically used to replace those $abc$ tokens in the .nuspec file.

Even cooler– NuGet figured out the dependencies of our project and added those as well!

Updated NuGet

Want to make sure you have the latest version of NuGet?  Let’s NuGet… NuGet!  After all, NuGet is pretty awesome at updating packages, why not letting it updating itself?

nuget update -self

Your Thoughts?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s