简体   繁体   English

在 Visual Studio 构建和 nuget 恢复命令期间忽略 packages.config 文件

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

I am trying to setup automated nuget package restoration on a vs build or command line build.我正在尝试在 vs 构建或命令行构建上设置自动 nuget package 恢复。 When following the specified Microsoft article: https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore#migrate-to-automatic-package-restore-visual-studio遵循指定的 Microsoft 文章时: https://docs.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我无法让 Visual Studio 2019 或以下命令(nuget restore mysolution.sln、msbuild -t:restore、msbuild -restore)从我的每个项目中的 packages.config 文件中读取

I have tried the following:我尝试了以下方法:

  • removing any references to PackageReference in each of the project files删除每个项目文件中对 PackageReference 的任何引用

  • deleting the bin and obj folders in each project删除每个项目中的 bin 和 obj 文件夹

  • adding a local nuget.config with the following:添加具有以下内容的本地 nuget.config :

  • deleting the local packages folder删除本地包文件夹

  • deleting the global packages folder删除全局包文件夹

  • running the following command: nuget locals all -clear运行以下命令: 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" 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.重新启动 Visual Studio 几次。

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.当我为我的解决方案运行 nuget 恢复命令时,它尝试从每个项目文件中的 packagereference 恢复,但由于我没有任何内容,它什么也不做,但仍会创建相应的 nuget.g.props 和 project.assets.Z466DEEC76ECDF25FCA4D 文件。 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.我需要能够将 packages.config 文件与构建命令之一一起使用。 I am stumped as to why this is not working我很困惑为什么这不起作用

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.您必须从解决方案文件夹中删除.vs隐藏文件夹,它仍然恢复旧的 nuget 管理格式PackageReference ,并且仍然使用它。

Try the following steps:尝试以下步骤:

1) Close VS, delete .vs hidden folder and every bin and obj folder. 1)关闭VS,删除.vs隐藏文件夹以及每个binobj文件夹。

2) make sure the every packages.config is in the project folder so that it will work. 2)确保每个packages.config都在项目文件夹中,以便它可以工作。

3) If you use your own nuget.config, please make sure its package source contains all the nuget packages. 3)如果您使用自己的 nuget.config,请确保其 package 源包含所有 nuget 包。 Or the file is redundant, you should remove it and then add the nuget package source under VS IDE .或者文件是多余的,您应该将其删除,然后在 VS IDE 下添加 nuget package 源

3) restart VS, run update-package-reinstall under Tools --> Nuget Package Manager --> Package Manager Console 3)重启VS,在Tools下运行update-package-reinstall --> 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. 4)之后,您可以删除全局 nuget 文件夹和本地 nuget 文件夹,然后运行nuget restore xxx.sln进行检查。


EDIT: Make sure your project is not an SDK-style project;编辑:确保您的项目不是SDK 风格的项目; SDK projects are not supported with packages.config files (see this ). packages.config 文件不支持 SDK 项目(请参阅this )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM