This Visual Studio extension migrates packages.config to PackageReferences.
It works with C# csproj and native C++ vcxproj Visual Studio project files.
Download it from the Visual Studio Marketplace
- Download and install the extension.
- Right-click on
packages.config
and selectMigrate packages.config to PackageReferences...
.
- Wait until the process finishes.
Check the status bar or theMigrate packages.config to PackageReferences Extension
pane in theOutput Window
for details.
This extension will first create a backup of the project and packages.config
files.
For example, MyProject.vcxproj
and packages.config
will be copied to MyProject.vcxproj.bak
and packages.config.bak
respectively.
If the project and packages.config
files are source controlled, they will be checked out for modification.
The NuGet packages referenced in packages.config
will be migrated to the project file in the new PackageReference
format.
For example, the following elements in the vcxproj
project file:
<Import Project="..\packages\MyPackage.1.0.0\build\MyPackage.props" Condition="Exists('..\packages\MyPackage.1.0.0\build\MyPackage.props')" />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MyPackage.1.0.0\build\MyPackage.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MyPackage.1.0.0\build\MyPackage.props'))" />
</Target>
will be converted to this:
<ItemGroup>
<PackageReference Include="MyPackage" Version="1.0.0" />
</ItemGroup>
After the project file has been updated, packages.config
will be deleted, and the project reloaded.
Check the Migrate packages.config to PackageReferences Extension
pane in the Output Window
for detailed logs.
-
Visual Studio Developer Community Feedback: Use PackageReference in vcxproj
-
StackOverflow Question: PackageReference for NuGet packages in C++ projects
-
Github Repo: Example C++ project that uses NuGet PackageReference (instead of packages.config)
-
Microsoft Learn Docs: Migrate from packages.config to PackageReference
-
Software Meadows Blog Post: Revert PackageReference Project to Packages.config
-
Visual Studio 2017 Extension: NuGet PackageReference Upgrader
The feature built-into Visual Studio 2017 Version 15.7 and later does not support native C++ projects.
The following error appears:
Project is not eligible for migration. Either the project is not packages.config based or doesn't support PackageReference yet. Visit https://docs.microsoft.com/en-us/nuget/reference/migrate-packages-config-to-package-reference for more information.
Has this extension helped you at all?
If so, please rate and share it.
Thank you! :)