Publishing A Custom Library With the Nuget Package Explorer

This quick tutorial should be easy reading and all about getting a Nuget package published quickly using the Nuget Package Explorer tool. We'll also apply a web.config transform and make the library have a dependency.

Make sure you download the tool and if you're publishing to Nuget or another custom repository that you have signed up and have access to an API key.

The Library###

Imagine the following library that we're creating called MyLibrary :
mylibrary solution

It has a dependency on Rebus version 0.69.0 which we installed through the package manager and we want to make sure that this dependency is installed when we pull in when someone else goes to use this library.

We put the solution into Release mode and then build it. So your dll should look like this:
release build

We will need to reference this location later for our package.

Since it depends on Rebus, we need a web.config transform to tell us where our endpoint is for the messages to go using MSMQ. To add the transforms automatically to whatever solution is pulling in our package we can add a web.config.transform file. The Nuget documentation indicates the .transform extension will add the desired nodes for us.

    <section name="rebus" type="Rebus.Configuration.RebusConfigurationSection, Rebus" />
  <rebus inputQueue="MyLibraryQueue.input" errorQueue="MyLibraryQueue.error">
      <add messages="MyLibrary" endpoint="ENDPOINT_QUEUE_NAME.Input@TARGET_MACHINE_NAME" />

Step 1. Edit the Metadata####

When we first run the application just select Create New Package. There is a meta-data file there which is pretty simple to fill out. The default version number is 1.0.0. Note that each time we re-publish our library, we should increase the version number and save the file. It will generate a new .nupkg later for us which we can edit again later with the Package Explorer.

Step 2. Add Dependencies####

When editing the Metadata file there is a button at the bottom to add dependencies. This is where we include Rebus. The nice thing about this is that clicking on the icon will get us to's repository where we can search for Rebus.

The MyLibrary solution is written in .NET 4.0 so we'll need to add net40 as the targetted framework. The screen should look as follows:

edit dependencies

Step 3. Add the files####

The documentation on specifies that the transform should sit under a content folder. Under the tools menu you can also add a lib folder where the dll will sit.

The nice thing about the Package Exporer is that if you hit alt+Q it will run an analysis of your package to see if there are any errors.

package explorer analysis error

Here, I get a warning because I didn't put the library dll inside a framework folder. The dll is from the release folder that we built earlier.

After fixing up the structure, the final solution should look like this:

package final solution

Nice. We've got the dependency, we've got the library and the transforms. All that's left is the publish.

Step 4. Publishing The Library####

If you're adding the library to your custom repository or the official Nuget repo, you'll still need an API Key. All that's left is clicking on File->Publish :

publish package

If you save this package it will generate a .nupkg file. You can always go back in and edit the package again and increment the version number.

Nice and easy.