Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I revert to referencing Nuget packages in packages.config after using Package References in a .NET Standard project?

Background

I have several C# code libraries which I recently converted to target .NET Standard 1.4, for use in a Xamarin Forms project as well as many legacy .NET Framework 4.6.1 projects.

I initially added Nuget packages to the .NET Standard class libraries using the Package Reference in Project Files style.

After learning of this bug where transitive package references from .NET Standard projects are not resolved in legacy .NET Framework projects, I tried the workaround of adding <RestoreProjectStyle>PackageReference</RestoreProjectStyle> to the legacy project's csproj. The legacy projects continued to not resolve the transitive references- that is, the workaround didn't work.

So, I would like to revert to the old style of referencing Nuget packages in a packages.config file in my .NET Standard project.

Steps I followed:

  • Uninstalling all Nuget packages in the .NET Standard project, except NETStandard.Library which cannot be uninstalled
    • My VS default setting for Nuget is to add the first package in a solution to packages.config
  • Reinstalling a Nuget package from the Manage Nuget Packages tool window
    • This package is placed in the csproj as a PackageReference, not in a packages.config file.

Does anyone know how I can force new Nuget packages in my .NET Standard 1.4 project to be listed in packages.config instead of as Package References?

like image 268
Cass Avatar asked Jul 21 '17 18:07

Cass


2 Answers

How to roll back to packages.config

  1. Close the migrated project.

  2. Copy the project file and packages.config from the backup (typically \MigrationBackup\\) to the project folder. Delete the obj folder if it exists in the project root directory.

  3. Open the project.

  4. Open the Package Manager Console using the Tools > NuGet Package Manager > Package Manager Console menu command.

  5. Run the following command in the Console:

    update-package -reinstall

Source: https://docs.microsoft.com/en-us/nuget/reference/migrate-packages-config-to-package-reference#how-to-roll-back-to-packagesconfig

like image 25
Paulo Pozeti Avatar answered Sep 22 '22 13:09

Paulo Pozeti


In addition to removing the PackageReferences from the project file, I also had to remove the following files from the $ProjectDir\obj directory:

  • Myproject.csproj.nuget.cache
  • Myproject.csproj.nuget.g.props
  • Myproject.csproj.nuget.g.targets
  • project.assets.json
like image 82
BenV Avatar answered Sep 21 '22 13:09

BenV