Switching from packages.config to PackageReference for .NET projects

Recently NuGet introduced a new way of handling packages within a project. Instead of stuffing references in a separate packages.config file, it introduced storing package references right in the project file instead.

There are several benefits (really, read the hyperlinked document) to that, the biggest one from my perspective is that it doesn't pollute NuGet packages list anymore. Previously, if you installed a package that referenced many transitive packages, then the package manager would show all of them at the same level. The worse case was when you referenced a .NET Standard package to a Xamarin application - in that case you could end up with like 20+ additional packages.

Example: adding (my favorite IoC container) Autofac to a Xamarin Android project would yield all these guys:


Not funny, eh?

So, the PackageReference way will still reference all those but it won't pollute your NuGet packages list anymore. Plus it clearly shows the top level packages under references, like this:

How does one turn on PackageReference mode?

For new projects

I suggest you set PackageReference as default mode using Tools/Options.../NuGet Package Manager window. Note that default is still package.config.

For existing projects

you should migrate packages.config file as described here. You need Visual Studio 2017 Preview 3 or newer.

That's it - no more polluted lists and many other benefits!


Loading