Switch back to packages.config

11.8k views Asked by At

Is it possible to switch back to packages.config scheme of things? I moved to PackageReference scheme when I created the project, but for some reasons need to move to old way of things now.

I have tried Package Manager Console commands like restore with Update and Reinstall options. They do not generate packages.config anymore. I also switched Tools > Options > NuGet Package Manager to packages.config. No good.

5

There are 5 answers

8
Martin Ullrich On BEST ANSWER

You'll need to:

  1. Add an "empty" packages.config file to the project (that is, xml as in the example but without individual <package> elements)
  2. Unload the project or close vs and open the csproj file in a text editor.
  3. Remove all PackageReference elements out of the project file.
  4. Make sure that <RestoreProjectStyle> is not set in the project file.
  5. Reopen the project in VS.
0
cr1pto On

I did this and was doing some nuget bundling and noticed that my dependencies were not coming over and decided to rollback and found this helpful article from Microsoft:

How to roll back to packages.config

Close the migrated project.

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

Open the project.

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

Run the following command in the Console:

update-package -reinstall

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

This is actually saving me right now and I wanted to post this just in case others had a similar problem.

0
Miroslav Mikus On

There was one step missing for me:

4.5. Make sure that Tools>Options>NuGet Package Manager>General>Default package management format is set to Packages.config

0
Ian Sullivan On

Wanted to add one more thing. I tried all above steps and Visual Studio kept trying to use the global-packages location, instead of repositoryPath from Nuget.config. Finally found that there was a package-lock.json file in the obj dir of my projects that had the global package dir stored in it. For some reason the Clean operation, in Visual Studio, didn't delete the file, so I wound up doing a

git clean -x -d -f

At the root of my repository. Which deletes all un-tracked files and directores, and ignores the patterns the .gitignore file. It was a bit excessive, I could have tried to find them all by hand, but it got the job done. Now Nuget restore properly uses the repositoryPath setting specified in the Nuget.Config file.

0
Mobz On

How I made it work:

  1. Take of screenshot of the packages we use in this project
  2. Add an "empty" packages.config file to the project and copy this into it:
<?xml version="1.0" encoding="utf-8"?>
<packages>
</packages>
  1. Unload the project and open the csproj file in a text editor.

  2. Remove all PackageReference elements out of the project file.

  3. Make sure that <RestoreProjectStyle> is not set in the project file.

  4. Make sure that:

    Tools > Options> NuGet Package Manager > General> Default package management format is set to Packages.config

  5. Delete the obj folder in the project

  6. Use the screenshot to re-download the packages again