我正在尝试通过 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,我无法安装任何其他工具。
我尝试指定版本,但仍然不起作用 我尝试了很多事情:
我可以访问 https://api.nuget.org/v3/index.json 所以这不是我的互联网连接问题。
它看起来像
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
需要检查的一件事是主 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
我也有类似的问题。对我来说解决这个问题的是删除
<packageSourceMapping>
中的 %appdata%\Nuget\NuGet.Config
标签。