[英]NuGet package refuses to uninstall in .NET Core library
I'm creating a .NET Core xUnit test project library in VS2017. 我正在VS2017中创建一个.NET Core xUnit测试项目库。 I accidentally installed the System.Collections.Immutable NuGet package, and now I want to uninstall it.
我不小心安装了System.Collections.Immutable NuGet包,现在我想卸载它。
First, I tried editing the csproj
file and removing this line: 首先,我尝试编辑
csproj
文件并删除此行:
<PackageReference Include="System.Collections.Immutable" Version="1.3.1" />
That didn't work, since the types from that package were still highlighted in the editor. 这不起作用,因为该包中的类型仍然在编辑器中突出显示。 So I tried running
Uninstall-Package System.Collections.Immutable
in the Package Manager Console. 所以我尝试在Package Manager Console中运行
Uninstall-Package System.Collections.Immutable
。
The console said it couldn't find the package, so I tried putting the <PackageReference...
line above back and running Uninstall-Package
again. 控制台说它找不到包,所以我尝试将
<PackageReference...
行放在上面并再次运行Uninstall-Package
。 The console said the uninstall succeeded, but VS still recognized the types. 控制台说卸载成功,但VS仍然认识到类型。
I tried closing VS, deleting .vs/
, and reopening. 我尝试关闭VS,删除
.vs/
,并重新打开。 It still recognized the types. 它仍然认识到这些类型。
I tried git stashing my changes, running git clean -xdf
, and running dotnet restore
from the command line. 我试过git stashing我的更改,运行
git clean -xdf
,并git clean -xdf
运行dotnet restore
。 Somehow, it still outputs 不知何故,它仍然输出
$ dotnet restore Restoring packages for C:\\cygwin64\\home\\james\\Code\\cs\\BlockList\\src\\BlockList\\BlockList.csproj... Restoring packages for C:\\cygwin64\\home\\james\\Code\\cs\\BlockList\\src\\BlockList.Tests\\BlockList.Tests.csproj... ... Installing System.Collections.Immutable 1.2.0. Installing System.Collections.Immutable 1.3.0. ...
I also tried restoring from Visual Studio instead of the command line. 我也尝试从Visual Studio而不是命令行恢复。 Still no luck.
仍然没有运气。
When I searched all the files in my repo for the word Immutable
, the only thing popping up is project.assets.json
in the obj
directory. 当我搜索我的仓库中的所有文件中的单词
Immutable
,弹出的唯一内容是obj
目录中的project.assets.json
。 Not a single source file contains the word Immutable
. 没有一个源文件包含单词
Immutable
。 I'm confused, then, as to how it's still being referenced. 那么,我很困惑,至于它是如何被引用的。 How can I uninstall it?
我该如何卸载它?
A few other things: 其他一些事情:
I checked the 'Dependencies' drop-down for my project in Solution Explorer, and it's not listed there. 我在解决方案资源管理器中检查了我的项目的“依赖关系”下拉列表,但它没有列在那里。
I don't want to delete my local copy of the repo and re-clone it, since I have other work stashed. 我不想删除我的本地副本并重新克隆它,因为我还有其他工作被隐藏起来。
System.Collections.Immutable.dll
doesn't show up at all in the bin/
directory, yet when I use one of the types in my library and run it, it works fine. System.Collections.Immutable.dll
根本没有显示在bin/
目录中,但是当我使用我的库中的一种类型并运行它时,它工作正常。
Thanks! 谢谢!
edit: Adding this line to the library: 编辑:将此行添加到库中:
System.Diagnostics.Debug.WriteLine(typeof(ImmutableArrayExtensions).GetTypeInfo().Assembly.Location);
And running it says that the assembly is located in this location: 运行它说组件位于这个位置:
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.2\System.Collections.Immutable.dll
After about an hour, I found out what the problem was. 大约一个小时后,我发现了问题所在。 My .NET Core library referenced
Microsoft.NETCore.App
, which referenced System.Collections.Immutable
. 我的.NET Core库引用了
Microsoft.NETCore.App
,它引用了System.Collections.Immutable
。 I looked at the dependencies for the former, but overlooked System.Collections.Immutable
because that package references maybe 50 other packages. 我查看了前者的依赖关系,但忽略了
System.Collections.Immutable
因为该包引用了其他50个包。 I ended up finding this out by creating a brand-new xUnit test project, and trying to see if ImmutableArray<>
was present without installing anything. 我最终通过创建一个全新的xUnit测试项目找到了这一点,并试图看看
ImmutableArray<>
是否存在而没有安装任何东西。 Sure enough, I could use it out of the box. 果然,我可以开箱即用。
I had a similar issue with VS2017 and a different nuget package that wouldn't fully uninstall. 我有一个与VS2017类似的问题和一个不能完全卸载的不同的nuget包。 I ultimately had to create a new project and cut and paste all my code into it.
我最终不得不创建一个新项目,并将所有代码剪切并粘贴到其中。 Kind of a sledge hammer approach, but faster than crawling through dependencies.
一种大锤方法,但比爬行依赖更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.