Few days back i was working on to upgrade the Sitecore project to use PackageReference instead of packages.config and the migration was smooth except one glitch.
There are several advantages we get with PackageReferences, few of them are as follows:
- Faster package install and update times.
- Ability to manage all project dependencies from single place (project file).
- Top-level view of dependencies, the project file shows only those NuGet packages you directly installed in the project.
When moved to PackageReferences you are going to get rid off packages.config and all references are going to be part of project file.
The references which we see above with packages.config will be removed and gets added to project file just like any other file in the project.
Above screen shot shows how it looks when it gets added to project file.
Another advantage we get with PackageReference is that all the packages gets referred from global folder instead of having separate packages folder for all the solutions and this overall improves the performance and save some disc space as well.
Migrate to PackageReference from packages.config
If you already have a solution that is based on packages.config follow the below steps to make it compatible with PackageReference.
- Go to Tools ->Options- > Nuget Package Manager and change the Default package management format to “PackageReference“, we have two options there- Packages.config and PackageReference.
- Once the format is change to PackageReference, you can go to the project which you want to migrate and click on packages.config.
- Right click on packages.config and click on Migrate packages.config to PackageReference.
- You can also click on References and get to the same option to migrate.
- It would list down all the top level dependencies and transitive dependencies and also shows if there are any compatibility issues with the migration.
- Once you see everything is ok to proceed, click on OK, it might take few seconds to migrate and generate the backup folder before migrating the project which gets added to the solution root for you to roll back if required.
- Once the migration is completed- we can see the changes there:
Another important thing to note here, PackageReference option is available with Visual Studio 2017 and later.
Troubleshooting:
I got one issue while migrating to PackageReference, related to project not eligible for migration.
Everything looks fine to me, after spending some time i was able to fix this issue by following the below suggestion:
https://github.com/NuGet/docs.microsoft.com-nuget/issues/860#issuecomment-409207305
Overall i feel it’s worth to migrate to PackageReference considering the advantages we get with it over packages.config, i would say definitely give it a try.
Hope this helps!
Happy learning
References:
https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference
https://github.com/NuGet/docs.microsoft.com-nuget/issues/860#issuecomment-409207305
Comments
Post a Comment