How can I go back to referencing Nuget packages in .config packages after using package referencing in a .NET Standard project?

Background

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

First, I added Nuget packages to the .NET Standard Class Libraries using the Package Reference in Project Files .

After investigating this error where links to transitional packages from .NET Standard projects are not allowed in older .NET Framework projects , I tried a workaround to add <RestoreProjectStyle>PackageReference</RestoreProjectStyle>

csproj to the legacy project. Legacy projects continued not to resolve transient references, i.e. The workaround didn't help.

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

Sequence of steps:

  • Removing all Nuget packages in a .NET Standard project except NETStandard.Library which cannot be removed
    • My VS default setup for Nuget is to add the first package to the solution package.config
  • Reinstalling Nuget Package from Tool Window Manage Nuget Packages

    • This package is placed in csproj as PackageReference

      , not in package.config file.

Does anyone know how I can get the new Nuget packages in my .NET Standard 1.4 project to be listed in packages.config

instead of package references?

+4


source to share


4 answers


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

:



  • Myproject.csproj.nuget.cache
  • Myproject.csproj.nuget.g.props
  • Myproject.csproj.nuget.g.targets
  • project.assets.json
+2


source


If you haven't removed this property yet: <RestoreProjectStyle>PackageReference</RestoreProjectStyle>



And then remove any PackageReferences in your project. Then when you add references to the nuget package, they should go into the package.config file.

0


source


How to rollback to packages.config

  1. Close the migrated project.

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

  3. Open your project.

  4. Open the Package Manager Console by 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

0


source


  1. remove all PackageReference in the project file.
  2. deleting all caches in $ ProjectDir \ obj.
  3. add an empty packages.config file (with root tags) to the project.
  4. rebuild the project. Then Visual Studio will tell you what is missing.
  5. Then add the package of the selected version using the Nuget Manager.
  6. Repeat steps 4 and 5, VS will add your link one by one back to the packages.config file.
0


source







All Articles