Recently during a .Net upgrade project, we migrated NuGet packages to PackageReference. Though we have been using NuGet packages for a long time, it has been interesting to see how NuGet has changed the way of including packages without package.config. The new method keeps solutions tidier and has numerous other advantages, so it’s definitely worth checking out.
How is it different?
Here are some differences between PackageReference and traditional package inclusion:
No more packages.config in your solution
Package references are directly added in your application just like other files, so no more packages.config.
No more long lists of dependencies (my personal favorite)
Earlier, a package inclusion would include all dependent references as well, making it very difficult to spot the ones you included. Now with PackageReference, you only see the one you actually added.
Refers packages from a global repository
Packages are referred from a global repository folder instead of a local solution folder. This saves space and improves performance.
Helps distinguish between packages and other references
Unleash the Potential of Power Platform With a Center of Excellence
Business innovation often comes from within. Discover how to empower innovation from non-traditional developers with the Microsoft Power Platform.
Visual separation is a great way to see packages.
Only compatible with Visual Studio 2017 and later
With Visual Studio 2019 already being available, I don’t feel this is a cost. Rather, it encourages you to adopt newer technologies.
For new package references in Visual Studio, you need to set Default Package Management Format to PackageReference by going to:
- Tools > NuGet Package Manager > Package Manager Settings
- Tools > Options; Under General tab in Package Manager Settings
For existing references, you can migrate easily by right clicking on the config file, and selecting “Migrate packages.config to PackageReference…”
With all of the benefits and easy migration steps, it is worth switching to PackageReference.