无法使用dotnet工具安装命令安装任何内容。

5
我正在尝试通过dotnet-cli安装dotnet-ef工具。
我输入的命令是:dotnet tool install --global dotnet-ef
它给了我以下错误提示:
   C:\Users\%USERNAME%\AppData\Local\Temp\147383a8-b714-4336-bb96-30c0670ea37d\restore.csproj : error NU1211: Project res
tore must have a single package reference(s).
C:\Users\abby.rahimi\AppData\Local\Temp\147383a8-b714-4336-bb96-30c0670ea37d\restore.csproj : error NU1212: Invalid pro
ject-package combination for Microsoft.DotNet.Analyzers.Compatibility 0.2.12-alpha. DotnetToolReference project style c
an only contain references of the DotnetTool type
The tool package could not be restored.
Tool 'dotnet-ef' failed to install. This failure may have been caused by:

* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.

不仅仅是EF,我无法安装任何其他工具。

我尝试指定版本,但仍然无法正常工作。 我尝试了很多方法:

  • dotnet tool install -g dotnet-ef --ignore-failed-sources
  • 重新安装dotnet sdks(3.1和6.0.305)
  • dotnet tool uninstall --global dotnet-ef,然后再次尝试安装
  • 从C:\ Users%USERNAME%.dotnet \ tools中删除可执行文件dotnet-ef.exe
  • 在PowerShell和Win CLI中运行命令

我可以访问https://api.nuget.org/v3/index.json,所以这不是我的互联网连接的问题。


你有没有可能安装其他的包/工具?还是只有这个特定的包/工具在安装时出现问题? - ajawad987
不行,我不能安装任何其他的软件包或工具。 - Abby
2个回答

11
看起来像是dotnet tool遍历了nuget.config中的源,当一个失败时,它不会继续处理下一个。
在我的情况下,它失败是因为我有一个需要身份验证的私有源(尽管已在nuget.config中配置)。
感谢@wli3提到使用--ignore-failed-sources,像这样使用:
dotnet tool install -g nbgv --ignore-failed-sources

哪个起了作用。原始链接: https://github.com/dotnet/sdk/issues/16215#issuecomment-791796542


3

需要检查的一件事是主要的NuGet源是否已配置使用dotnet SDK。通常默认情况下应该有https://api.nuget.org/v3/index.json这个源, 但可能出了些问题,源列表被搞乱了。

首先要检查的是您的安装中配置了哪些源,可以通过运行以下命令来查看:

dotnet nuget list source

如果您在标准的https://api.nuget.org/v3/index.json路径中没有看到源代码,您可以使用以下命令行将其添加回来:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org

注意:您可以使用-n开关随意命名源名称。
另一件需要检查的事情是源是否已禁用。如果是这样,您可以使用以下命令重新启用它:
dotnet nuget enable source nuget.org

1
谢谢,但我已经做了那个,还是没有任何区别。以下是列表:已注册的源: 1. nuget.org [已启用] https://api.nuget.org/v3/index.json 2. my-private-source [已启用] https://nuget.pkg.github.com/myprivatesource/index.json - Abby

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接