packages.config file is ignored during Visual Studio Build and nuget restore commands

4.2k views Asked by At

I am trying to setup automated nuget package restoration on a vs build or command line build. When following the specified Microsoft article: https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#migrate-to-automatic-package-restore-visual-studio

I am unable to get Visual Studio 2019 or the following commands (nuget restore mysolution.sln, msbuild -t:restore, msbuild -restore) to read from a packages.config file in each of my projects

I have tried the following:

  • removing any references to PackageReference in each of the project files

  • deleting the bin and obj folders in each project

  • adding a local nuget.config with the following:

  • deleting the local packages folder

  • deleting the global packages folder

  • running the following command: nuget locals all -clear

  • Updated Visual Studio -> Tools -> Options -> NuGet Package Manager and set "Allow Nuget to download missing packages" and "Automatically check for missing packages during build in Visual" and set the Default Package management format to "Packages.config"

  • Restarting Visual Studio a few times.

When I run the nuget restore command for my solution it attempts to restore from packagereference inside each of the project files but since I do not have any it does nothing but still creates the corresponding nuget.g.props and project.assets.json files. I cannot use packagereferences inside of project files since this is not portable to other projects.

I require the ability to use packages.config file with one of the build commands. I am stumped as to why this is not working

1

There are 1 answers

3
Mr Qian On BEST ANSWER

You have to delete the .vs hidden folder from the solution folder, it still restores the old nuget management format PackageReference, and still use it.

Try the following steps:

1) Close VS, delete .vs hidden folder and every bin and obj folder.

2) make sure the every packages.config is in the project folder so that it will work.

3) If you use your own nuget.config, please make sure its package source contains all the nuget packages. Or the file is redundant, you should remove it and then add the nuget package source under VS IDE.

3) restart VS, run update-package -reinstall under Tools-->Nuget Package Manager-->Package Manager Console

4) After that, you can delete global nuget folder and local nuget folder and then run nuget restore xxx.sln to check it.


EDIT: Make sure your project is not an SDK-style project; SDK projects are not supported with packages.config files (see this).