简体   繁体   English

Visual Studio 引用显示未引用的 NuGet 包

[英]Visual Studio References shows NuGet package that is not referenced

I converted a .NET Framework 4.7.2 project from packages.config to PackageReferences format by right clicking the packages.config file within VS 2019.我通过右键单击 VS 2019 中的 packages.config 文件,将 .NET Framework 4.7.2 项目从 packages.config 转换为 PackageReferences 格式。

Since then Visual Studio shows blue icons of a NuGet package which I uninstalled from the project in the References node.从那时起,Visual Studio 显示了一个 NuGet 包的蓝色图标,我在 References 节点中从项目中卸载了该包。 What is truly weird is that without this package the build should fail as it is used within the code, but the build succeeds!真正奇怪的是,如果没有这个包,在代码中使用它时构建应该会失败,但是构建成功了!

  1. There are no packagereference to this NuGet package in the .csproj file. .csproj 文件中没有对此 NuGet 包的包引用。
  2. There is no packages.config file in the project directory项目目录下没有packages.config文件
  3. I deleted the .vs folder and the older packages folder我删除了 .vs 文件夹和旧的包文件夹
  4. Restarted Visual Studio重新启动 Visual Studio
  5. Problem Remains问题仍然存在
  6. uninstall-package command fired within Visual Studio says the package is not installed.在 Visual Studio 中触发的 uninstall-package 命令表示未安装该软件包。
  7. Yet the Reference (Blue Icon) is shown and the project builds!然而,显示参考(蓝色图标)并且项目构建!

Question

  1. How do I completely remove this package from the project?如何从项目中完全删除这个包?
  2. How do I stop Visual Studio from referencing this package for now?我现在如何阻止 Visual Studio 引用此包?

=============================== ================================

If your project does not reference any other projects or just reference a project which does not install the same nuget package, I think the issue is related to your project itself or VS environment.如果你的项目没有引用任何其他项目,或者只是引用了一个没有安装相同 nuget 包的项目,我认为问题与你的项目本身或 VS 环境有关。

And in this situation, it is quite strange that the blue icon of the nuget package still stays on the solution explorer while you have already uninstalled the nuget package.在这种情况下,很奇怪的是,当您已经卸载了 nuget 包时,nuget 包的蓝色图标仍然停留在解决方案资源管理器上。

Please try the following suggestions:请尝试以下建议:

1) disable any third party extensions under Extensions --> Manage Extensions --> Installed 1)Extensions --> Manage Extensions --> Installed下禁用任何第三方扩展

2) clean nuget caches and reset vs settings under Tools --> Import and Export settings --> Reset all settings 2) 清理 nuget 缓存并在工具下重置 vs 设置 -->导入和导出设置-->重置所有设置

3) then close VS, delete cache files under 3)然后关闭VS,删除下缓存文件

C:\Users\xxx(current user)\AppData\Local\Microsoft\VisualStudio\16.0_xxx\ComponentModelCache

and also delete .vs hidden folder, bin and obj folder.并删除.vs隐藏文件夹、 binobj文件夹。

4) then restart VS to test whether the issue persists. 4)然后重启VS测试问题是否依然存在。

Besides , you could use devenv /safemode to start a clean and initial VS and then test your project.此外,您可以使用devenv /safemode启动一个干净的初始 VS,然后测试您的项目。

================================= ==================================

If your situation is this one:如果你的情况是这样的:

Your project B has referenced a project called Project A while A has also installed the same nuget package.您的项目 B引用了一个名为Project A 的项目,而 A 也安装了相同的 nuget 包。 And project A uses PackageReference nuget management format .并且项目 A使用PackageReference nuget 管理格式

Although you have uninstall the nuget package on Project B, your obj folder still has files like project.assert.json , xxx.nuget.g.props which is a feature of PackageReference .尽管您已经卸载了项目 B 上的 nuget 包,但您的obj文件夹中仍然包含project.assert.jsonxxx.nuget.g.props等文件,这是PackageReference 的一个功能。 Due to it, the nuget package management format of Project B is the same as the Project A and will transmit the dll from the Project A into Project B so that you can use the dll in the project B .由于它,项目B的NuGet包管理格式是一样的项目A,并从项目中的dll传递到B项目,这样就可以在项目B使用的DLL。

And that delete .vs hidden folder will remove the nuget package format PackageReference of Project B since you already uninstall all the nuget packages on Project B but the PackageReference content of obj folder still exist.删除.vs既然你已经卸载所有的项目B的包的NuGet但对PackageReference内容隐藏文件夹将删除项目B的NuGet包格式PackageReference obj文件夹仍然存在。

So you should close VS, delete .vs hidden folder, bin and obj folder of the Project B at the same time.所以你应该关闭VS,同时删除Project B的.vs隐藏文件夹、bin和obj文件夹。

Note : Rebuild and Clean will not delete the previous restore files.注意重建和清理不会删除以前的还原文件。

If this does not work, I think you have written this xml node under B.csproj file:如果这样不行,我想你已经在B.csproj文件下写了这个 xml 节点:

<PropertyGroup>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>  

So you should check in your project B carefully and it will still restore the files project.assert.json , xxx.nuget.g.props ,.... as PackageReference .所以你应该仔细检查你的项目 B,它仍然会恢复文件project.assert.jsonxxx.nuget.g.props ,.... 作为PackageReference

Therefore, if you have, delete this node, also delete .vs hidden folder, bin and obj folder.因此,如果有,请删除此节点,同时删除.vs隐藏文件夹、 binobj文件夹。

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

相关问题 Visual Studio中的Nuget引用 - Nuget references in Visual Studio Visual Studio 2015 - NuGet包删除所有项目引用 - Visual Studio 2015 - NuGet package removes all project references 找不到引用的Nuget DLL,可以在Visual Studio中正常工作 - Referenced Nuget DLL Not Found Working Visual Studio Nuget 包未在 Visual Studio 中更新 - Nuget package not updating in Visual Studio 在Visual Studio 2015中使用NuGet安装软件包后,无法在参考中找到Math.net - Cannot find Math.net in References after installing package with NuGet in Visual Studio 2015 我已经使用NuGet在Visual Studio 2013中安装了SQLite,但该包从未出现在“引用”中 - I've installed SQLite in Visual Studio 2013 using NuGet but the package never appears in References Visual Studio Professional 2012错误:此项目引用ASP.NET MVC项目中缺少的NuGet包 - Visual Studio Professional 2012 error: This project references NuGet package(s) that are missing in ASP.NET MVC project Nuget package 在参考项目中更新,但仍显示旧项目 - Nuget package updated in a referenced project but still shows the old one Visual Studio 在我的所有例程中都没有显示任何引用 - Visual Studio shows no references on all my routines Visual Studio错误地将wwwroot打包在NuGet包中 - Visual Studio incorrectly packs wwwroot in NuGet package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM