How to Update C# Dependencies 💪

If you want to update your package dependencies for your .NET project, you can manually update them in your .csproj file. Or you could just ask your IDE to update them. 😎

3 min read
How to Update C# Dependencies 💪
A person trying to keep their dependencies up to date. Photo by Tima Miroshnichenko from Pexels.

In my previous article, you learn how to update your projects to .NET 6, but I didn't take the time to write about updating your dependencies as well.  🙈

Yes, even if your project continues to run, it might be a good idea to update your NuGet packages from time to time. Not only will you get the latest improvements, but you'll also get security patches if there are any. 🤗

But, how do we do this? 🤔

It turns out that your IDE can help you keep your dependencies up to date. 😍

💡
While you're at it, you might want to take a look at locking down your C# dependencies. Doing this will ensure that everyone, including your builds on CI/CD platforms, has the exact same version of all dependencies. Aka a reproducible build.

Visual Studio

🌎
You may notice in my screenshots that Visual Studio seems to be installed in French, I'm sorry. But I'm sure that with the attached notes you'll quickly understand.

If you're using Microsoft's official IDE, Visual Studio, the procedure is quite simple. It only has five steps:

  • In the top menu of the IDE, click ToolsNuGet Package ManagerManage NuGet Packages for Solution....
Screenshot showing how to open the NuGet - Solution window in Visual Studio.
  • In the upper right of the new window named Nuget - Solution, click on to the Updates tab.
  • Make sure that Package Source is set to All.
Screenshot showing how to update NuGet packages in Visual Studio.
  • Click on the Update button to update all libraries.
  • Launch your app and make sure it's still working properly.

Really simple, right? 😆

JetBrains Rider

If you are using JetBrains Rider as your IDE, the process is very similar:

  • In the top menu of your IDE, click on ToolsNugetShow Nuget Packages.
Screenshot showing how to display the NuGet window in JetBrains Rider.
  • A new window will appear that lists all the installed packages in your project and their respective version, next to their name. On the right, you'll see their latest version available.
Screenshot showing installed packages along with their current and latest version in JetBrains Rider.
  • On the left of the NuGet window, click on the Upgrade Packages in Solution button (with the circled arrow).
Screenshot showing how to upgrade your NuGet packages in JetBrains Rider.
  • Select all the packages you want to update.
  • Click on the Upgrade button to update all selected dependencies.
  • Finally, make sure your application still builds and runs as before.

There you go, your dependencies are now up to date! 🥳

Manual file editing

Again, if you look at the only modified file, the YOUR_PROJECT.csproj file, you might notice that we could just modify it as well. 😮

Screenshot showing the differences in the .csproj file after our changes.

But it's easier to use the UI tool, isn't it? 😉

Conclusion

Don't forget to update your dependencies from time to time, otherwise, you could have security holes! A good rule of thumb is to do this every three months at least. 🧐

Unless there is a lot of breaking changes, it should only be a matter of minutes now that you know how to do it. 😉

Update them all! 🤣