[英]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!
真正奇怪的是,如果没有这个包,在代码中使用它时构建应该会失败,但是构建成功了!
Question题
=============================== ================================
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
隐藏文件夹、 bin
和obj
文件夹。
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.json
、 xxx.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.json
, xxx.nuget.g.props
,.... 作为PackageReference 。
Therefore, if you have, delete this node, also delete .vs
hidden folder, bin
and obj
folder.因此,如果有,请删除此节点,同时删除
.vs
隐藏文件夹、 bin
和obj
文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.