为什么我无法运行dotnet工具安装--global bla-bla-bla?

时间:2018-11-19 04:58:52

标签: windows .net-core

具体来说,我正在尝试运行dotnet tool install --global Project2015To2017.Migrate2017.Tool,如此处所述-enter image description here

这就是我得到的:

c:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.1.  Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. [C:\Users\mkharitonov\AppData\Local\Temp\3sdfphfy.fq0\restore.csproj]
The tool package could not be restored.
Tool 'project2015to2017.migrate2017.tool' 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 Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.

因此,我去了https://github.com/hvanbakel/CsprojToVs2017#as-a-net-core-global-tool并安装了SDK 2.1.500的.NET Core Installer x64。如果此方法不起作用,我为Runtime 2.1.6安装了相同的工具(不要认为它有任何作用)。无论如何,错误消息仍然存在,我不知道该怎么办。

编辑1

C:\xyz\MyApp [master ≡]> dotnet --list-sdks
1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk]
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]

编辑2

C:\xyz\MyApp [master ≡]> dotnet new globaljson --sdk-version 2.1.500
The template "global.json file" was created successfully.
C:\xyz\MyApp [master ≡ +1 ~0 -0 !]> cat .\global.json
{
  "sdk": {
    "version": "2.1.500"
  }
}
C:\xyz\MyApp [master ≡ +1 ~0 -0 !]> dotnet tool install --global Project2015To2017.Migrate2017.Tool
c:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.1.  Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. [C:\Users\mkharitonov\AppData\Local\Temp\lrfiazvp.bxe\restore.csproj]
The tool package could not be restored.
Tool 'project2015to2017.migrate2017.tool' 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 Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
C:\xyz\MyApp [master ≡ +1 ~0 -0 !]>

编辑3

C:\Users\mkharitonov\AppData\Local\Temp> dotnet --list-sdks
1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk]
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
C:\Users\mkharitonov\AppData\Local\Temp> Test-Path global.json
False
C:\Users\mkharitonov\AppData\Local\Temp> cd ..
C:\Users\mkharitonov\AppData\Local> Test-Path global.json
False
C:\Users\mkharitonov\AppData\Local> cd ..
C:\Users\mkharitonov\AppData> Test-Path global.json
False
C:\Users\mkharitonov\AppData> cd ..
C:\Users\mkharitonov> Test-Path global.json
False
C:\Users\mkharitonov> cd ..
C:\Users> Test-Path global.json
False
C:\Users> cd ..
C:\> Test-Path global.json
False
C:\>

1 个答案:

答案 0 :(得分:0)

您可以使用诊断详细级别运行 dotnet工具安装。 例如:

dotnet tool install --global Project2015To2017.Migrate2017.Tool -v diag

我遇到了一些问题,我遇到了错误:

The SDK 'Microsoft.NET.Sdk' specified could not be found

为解决此问题,我更改了环境变量 MSBuildSDKsPath (来自https://github.com/Microsoft/msbuild/issues/2532的建议)