奇怪的.NET Core SDK 2.2.6行为

时间:2019-08-06 17:05:52

标签: .net asp.net-core .net-core visual-studio-code visual-studio-2019

我学习了Azure认证,并开始研究Azure教程,该教程在其演示项目中使用.NET Core。实际上,我具有VS 2019(仅),并按如下所示安装了最新的.NET Core SDK(x64)

C:\Learning\MS-Certif-20-487\AzureToolkit>dotnet --info
A compatible SDK version for global.json version: [1.0.4] from [C:\Learning\MS-Certif-20-487\AzureToolkit\global.json] was not found

Host (useful for support):
  Version: 2.2.6
  Commit:  7dac9b1b51

.NET Core SDKs installed:
  2.1.102 [C:\Program Files\dotnet\sdk]
  2.1.103 [C:\Program Files\dotnet\sdk]
  2.1.104 [C:\Program Files\dotnet\sdk]
  2.1.200 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.400 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]
  2.1.403 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.503 [C:\Program Files\dotnet\sdk]
  2.1.504 [C:\Program Files\dotnet\sdk]
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.1.600-preview-009426 [C:\Program Files\dotnet\sdk]
  2.1.600-preview-009472 [C:\Program Files\dotnet\sdk]
  2.1.600 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

C:\Learning\MS-Certif-20-487\AzureToolkit>dotnet new globaljson --sdk-version 2.2.401
A compatible SDK version for global.json version: [1.0.4] from [C:\Learning\MS-Certif-20-487\AzureToolkit\global.json] was not found
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
  https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

C:\Learning\MS-Certif-20-487\AzureToolkit>

请注意最后一条命令,该命令要求使用最新的SDK构建新的global.json文件,看来dotnet无法识别它刚刚说已安装的SDK ...

最后,我的解决方案无法在VS 2019中打开,控制台中出现以下错误:

C:\Learning\MS-Certif-20-487\AzureToolkit\AzureToolkitWalkthrough.csproj : error  : 
The project file cannot be opened by the project system, because it is missing some 
critical imports or the referenced SDK cannot be found.

Detailed Information:
Unable to locate the .NET Core SDK. Check that it is installed and that the version 
specified in global.json (if any) matches the installed version.

在尝试调试项目时,Visual-Studio-Code也会给出以下错误

  

[信息]:OmniSharp.Stdio.Host           使用Stdio在主机4820上的位置'c:\ Learning \ MS-Certif-20-487 \ AzureToolkit'上运行的Omnisharp服务器。兼容   global.json版本的SDK版本:从[1.0.4]   找不到[c:\ Learning \ MS-Certif-20-487 \ AzureToolkit \ global.json]   [警告]:OmniSharp.MSBuild.ProjectManager           无法加载项目文件'c:\ Learning \ MS-Certif-20-487 \ AzureToolkit \ AzureToolkitWalkthrough.csproj'。   c:\ Learning \ MS-Certif-20-487 \ AzureToolkit \ AzureToolkitWalkthrough.csproj(1,1)   Microsoft.Build.Exceptions.InvalidProjectFileException:SDK   找不到指定的“ Microsoft.NET.Sdk.Web”。   c:\ Learning \ MS-Certif-20-487 \ AzureToolkit \ AzureToolkitWalkthrough.csproj   在   Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String   errorSubCategoryResourceName,IElementLocation elementLocation,字符串   resourceName,Object []参数)在   Microsoft.Build.Evaluation.Evaluator 4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List 1&   项目,SdkResult和sdkResult,布尔throwOnFileNotExistsError)
  在Microsoft.Build.Evaluation.Evaluator 4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult) at Microsoft.Build.Evaluation.Evaluator 4.EvaluateImportElement(String   directoryOfImportingFile,ProjectImportElement importElement),位于   Microsoft.Build.Evaluation.Evaluator 4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator 4.Evaluate(ILoggingService   loggingService,BuildEventContext buildEventContext)位于   Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService   loggingServiceForEvaluation,ProjectLoadSettings loadSettings,   评估上下文评估上下文),位于   Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService   loggingServiceForEvaluation,ProjectLoadSettings loadSettings,   评估上下文评估上下文),位于   Microsoft.Build.Evaluation.Project.Initialize(IDictionary 2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary 2 globalProperties,字符串工具版本,字符串   subToolsetVersion,ProjectCollection projectCollection,   ProjectLoadSettings loadSettings,EvaluationContext(valuationContext)   在Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String   fileName,IDictionary 2 globalProperties, String toolsVersion) at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore(String filePath) in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectLoader.cs:line 129 at OmniSharp.MSBuild.ProjectLoader.BuildProject(String filePath) in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectLoader.cs:line 72 at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load(String filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader) in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectFile\ProjectFileInfo.cs:line 95 at OmniSharp.MSBuild.ProjectManager.<>c__DisplayClass29_0.<LoadProject>b__0() in C:\projects\omnisharp-roslyn\src\OmniSharp.MSBuild\ProjectManager.cs:line 297 at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject(String projectFilePath, Func 1个加载程序)   C:\ projects \ omnisharp-roslyn \ src \ OmniSharp.MSBuild \ ProjectManager.cs:line   308

2 个答案:

答案 0 :(得分:2)

这很简单。您的主目录中或相对于解决方案或项目的某个路径中有一个global.json,该路径设置为使用.NET Core SDK /运行时的1.0.4。您没有安装1.0.4,所以会出现错误。 global.json文件会影响dotnet all 使用,因此尝试生成新的global.json也会失败。

简而言之,您只需要找到现有文件并将其手动更改为您已经安装的版本,或者将其完全删除即可,以使最新安装的SDK /运行时版本成为默认版本。

答案 1 :(得分:1)

  

与global.json版本兼容的SDK版本:从[1.0.4]   找不到[C:\ Learning \ MS-Certif-20-487 \ AzureToolkit \ global.json]

如该错误所示和建议,您的路径global.json中有一个C:\Learning\MS-Certif-20-487\AzureToolkit\。手动将其删除。

似乎您正在使用存储库AzureToolkit,对于此项目,它的目标是netcoreapp1.1。如果您正在学习Azure Storage APIs for .NET,建议您通过创建自己的asp.net核心项目来开始使用Azure Storage APIs for .NET,而不要使用旧的.net核心版本来克隆现有项目。由于您可能不熟悉Asp.NET Core和SPA项目模板,因此您可能会遇到其他问题。