NuGet–Upgrading your packages like a boss

How often do you get on a project and just to assess where are things… you open the “Manage NuGet Packages for Solution…” and go to the Updates tab.

Then… you see this.

image

I mean… there’s everything in there. From Javscript dependencies to ORM. You know that you are in for a world of trouble.

Problem

You see the “Update All” and it’s very tempting. However, you know you are applying all kinds of upgrades. This could be fine when starting a project but when maintaining an existing project… you are literally including new features and bugs fixes for all those libraries.

A lot can go wrong.

Solution A: Update All a.k.a. Hulk Smash

So you said… screw it. My client and me will live with the consequences. You press Update All and… everything still works on compile.

Congratulation! You are in the very few!

Usual case? Compile errors everywhere that you will need to fix ASAP before committing.

Worse case? Something breaks in production and it takes us to this:

code_test_meme

Solution B: Update safely a.k.a The Boss Approach

Alright… so you don’t want to go Hulk Smash on your libraries and on your code. And more importantly, you don’t want to be forced to wear the cowboy hat for a week.

So what is a developer to do in this case? You do it like a boss.

First, you open up “View > Other Windows > Package Manager Console”. Yes. It’s hidden but it’s for the pro. The kings. People like you who don’t use a tank to kill a fly.

It will look like this:

image

What is this? This beauty is Powershell. Yes. It’s awesome. There’s even a song about it.

So now that we have powershell… what can we do? Let me show you to your scalpel boss.

Update-Package is your best friend for this scenario. Here is what you are going to do:

1
Update-Package -Safe

That’s it.

What was done

This little “Safe” switch will only upgrade Revisions and will not touch Major and Minor versions. So to quote the documentation:

The ‘-Safe’ flag constrains upgrades to only versions with the same Major and Minor version component.

That’s it. Now you can recompile your app and most of your app should have all bug fixes for current Major+Minor versions applied.

like-a-boss

If you want to read more about Semantic Versioning (which is what NuGet uses), go read Alexandre Brisebois’ post on it. Very informative and straight to the point.