Switch back to packages.config

限于喜欢 提交于 2019-12-10 01:23:57

问题


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.


回答1:


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.



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/45962998/switch-back-to-packages-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!