Migrating NuGet packages.config file to a PackageReference
Posted: (EET/GMT+2)
Modern .NET Core applications support a .csproj feature called the PackageReference. This new XML element keeps your NuGet dependencies inside the project file, which makes restores faster and projects cleaner than the old packages.config. If you're using Visual Studio 2017 already, you can migrate the references in-place.
To migrate in Visual Studio, do this: right-click your project, select "Migrate packages.config to PackageReference", then review the preview and if everything looks good, click Apply. Your packages move into the .csproj and packages.config is removed.
If you prefer to edit the project file manually, you can add references directly to the .csproj like this:
<ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> <PackageReference Include="Serilog" Version="2.7.1" /> </ItemGroup>
After migration, delete the old packages folder under the solution, then restore the packages:
dotnet restore
Or in Visual Studio: select Build, then "Restore NuGet Packages".
Notes:
- Binding redirects are handled more cleanly, and transitive dependencies are resolved automatically.
- If a package is not compatible with PackageReference, the migration tool will warn you so you can pin or replace it.