From GitHub to Nuget via MyGet

Reading Time: 2 minutes

For Cors.ConfigProfiles, I wanted to try something I had seen before: automatically create a NuGet package when I push a new release to GitHub. To do this, I’d need a build server that would kick off when something changes in my master branch. If the build succeeds, it should look for a nuspec file (NuGet specification to build a package) and build that too, unless my build commands already took care of that. Then, I have a nupkg file: a NuGet package. The build server should then publish this new version to NuGet for me. And while we’re at it, it would be great if it would also take care of versioning my NuGet package for me, and tag the GitHub repository.

But I didn’t want to set all of this up by myself (developers are lazy, aren’t we?), so I made use of MyGet instead 🙂

On MyGet, you can configure a build service on a feed you own to start building code when a code repository changes. Currently, MyGet offers support for GitHub, BitBucket, CodePlex and Visual Studio Online, but only for Git, Mercurial or Subversion repositories. MyGet does support TFS environments, but only for Git repositories.
To get started, go to a feed or create a new one and click left on Build Services. Then, click on the big Add Build Source button and choose the source environment. If you select GitHub, you can select a repository after authenticating: check the “Link?” checkbox for each repository you want to build and click on the Add button. You can optionally choose to automatically start a build when code is committed, and to post a message back to GitHub when the build has completed.
By default, MyGet will build the master branch when the build service is triggered. You can change this when you click the Edit button:

Edit a build source

The edit dialog allows you to edit the branch, but also to change the versioning schema being used for your NuGet package. You can also include an increasing build number to make sure that you don’t try to push the same version to NuGet 🙂

MyGet - Edit versioning schema


A very nice addition here is the ability to update the assembly information of your project, so it matches the version of your NuGet package without having to remember to update it yourself!
There are even more options available:

  • to control the build process: which configuration should be build, which platforms and targets, which projects (*.csproj, *.sln, *.bat, …)…
  • which NuGet packages should be added or updated in your feed. By default, all packages that are not in a packages folder will be added, but you can limit this to a list of specific files.
  • whether to push symbol (*.pdb) packages as well, useful when debugging code that has been pulled in from NuGet packages
  • package and push sources

Now, you can trigger a build manually by pressing the Build button, or automatically by making a change and pushing the change to the correct branch.

The only thing I still need to do manually, is pressing the push button on MyGet to push the newest version of my package towards NuGet. Either using the Push Latest button at the top, or the small arrow in the bottom right corner:

MyGet - Push to NuGet

And that’s it!