I've recently been working on a few open source projects, namely JsonPatch support and HttpCache support for .NET as Portable Class Libraties; these are implementations of the JsonPatch spec & HttpCache spec respectively, and both are currently under active development. I had a few reasons for starting these; current implementations either didn't exist or didn't fully satisfy the needs I had for them (your mileage may vary, of course :)). As I currently use these in real-life projects, I figured they might be of use to other people as well, so: I wanted to make them available on NuGet.
I started out by manually creating the packages to upload to NuGet. It's a bit of a cumbersome process at first, but it's not that bad, so I was kinda happy.
After a while though, "kinda happy" evolved into "meh" :-) Surely, there had to be a way to automate this? I also hit a more important issue: I don't want to release every single commit as an update to my NuGet packages, yet I do like the way I can manage dependencies when they ARE available on NuGet. In fact, before considering an official release, I like to test these packages in the real-life projects I currently use them on (in a dev env, of course ;-)).
In short: I needed some sort of automation in creating these packages. I also required some sort of in-between private NuGet feed, so I could easily update packages in the projects I want to test them on before publishing them to "public NuGet".
That's where MyGet fits into this story. (just to be clear: no, I'm not getting paid to write this ;-))
My current workflow:
- Code in Visual Studio (where else? :))
- When a feature is done => GitHub
- Via a WebHook, MyGet auto-builds a new version of the package on each commit
- This package is available on my MyGet feed. I can use that to test.
- When it's time for a new version, I simply push the package that's already on MyGet to NuGet
Hours saved? Lots. Warm fuzzy feeling thanks to the fact that this all just works? Check! :)
Now, how do you do that? It's actually pretty easy to set up. Once you've got a MyGet feed, navigate to "Build Services". From there, you can select "Add build source...", and select "from GitHub".
You'll be asked to select the GitHub repo you want to link. Select it, and leave all the other options at default - MyGet will create a WebHook @ GitHub for you. And... that's it :-) From now on, a new MyGet package (incl the default semantic versioning – which is really nice) will be created each time you commit code changes to your GitHub repo.
Satisfied with the package, and want to push it to NuGet? Navigate to your package details => package history. There, choose the package you want to push to NuGet, and choose the Push option.
You’ll end up on this screen:
As you can see, in my workflow, that still includes a “pre-release”-tag. If you click the “Edit” button, you’ll see the pre-release tag is filled out:
I currently use my MyGet feed as one that contains pre-release feeds – thus, all my packages are pre-release, which explains why the pre-release tag is auto-filled out. If you use your MyGet feed as one that also hosts non-pre-release packages, and you push one of those to NuGet, the pre-release tag will be empty. So another strategy here (probably one that’s conceptually more correct ;-)) could be to ensure you’ve got a non-pre-release package at MyGet first, before pushing a version to NuGet.
Anyway, if you’re following my workflow and you want to make sure your package is not listed as a pre-release version on NuGet, click the “Edit” button and make sure you clear that tag.
By the way, MyGet automatically picks up your nuspec file from all the usual suspect locations (in my case, it's in the project dir itself) – that’s where the package details are coming from.
And that’s it – Push to publish your package to NuGet. Hope this helps some of you who are looking to automate their workflow out :)
If you want to help out on these projects, check GitHub.
If you want to access the in-between preview builds, these are my MyGet feed details - simply add the feed in VS's NuGet Package Manager options dialog. Make sure you select the "Include pre-release"-option in the Package Manager dialog, as that's what they are :)
And if you simply want to use these packages in your own projects, you can find 'm on NuGet.
Happy coding! :-)