VSCode 的 Omnisharp 1.9.0 扩展无法识别 DotNet Core 的 CSProj 文件
Omnisharp 1.9.0 extension for VSCode not recognize CSProj file for DotNet Core
当我尝试在 visual studio 代码中打开 dotNet core 1.1 mvc 项目时,无法识别 csproj 文件,我无法从项目中获取任何符号。
VSCode 显示 "Some projects have trouble loading, please review the output for more details" 的 [警告] 消息。在输出中我收到以下消息:
[warn]: OmniSharp.MSBuild.MSBuildProjectSystem
Failed to process project file 'c:\Users\humam\Projects\AM\AM.csproj'.
c:\Users\humam\Projects\AM\AM.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The imported
project "C:\Program Files (x86)\Microsoft Visual
Studio17\BuildTools\MSBuild\Sdks\Microsoft.NET.Sdk.Web\Sdk\Sdk.props"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
c:\Users\humam\Projects\AM\AM.csproj at
Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String
errorSubCategoryResourceName, IElementLocation elementLocation, String
resourceName, Object[] args) at
Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(IElementLocation
elementLocation, String resourceName, Object arg0) at
Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImportsFromUnescapedImportExpression(String
directoryOfImportingFile, ProjectImportElement importElement, String
unescapedExpression, Boolean throwOnFileNotExistsError, List
1&
imports) at
Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImports(String
directoryOfImportingFile, ProjectImportElement importElement) at
Microsoft.Build.Evaluation.Evaluator
4.EvaluateImportElement(String
directoryOfImportingFile, ProjectImportElement importElement) at
Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement
currentProjectOrImport) at
Microsoft.Build.Evaluation.Evaluator
4.Evaluate() at
Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService
loggingServiceForEvaluation, ProjectLoadSettings loadSettings) at
Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService
loggingServiceForEvaluation, ProjectLoadSettings loadSettings) at
Microsoft.Build.Evaluation.Project.Initialize(IDictionary2
globalProperties, String toolsVersion, String subToolsetVersion,
ProjectLoadSettings loadSettings) at
Microsoft.Build.Evaluation.Project..ctor(String projectFile,
IDictionary
2 globalProperties, String toolsVersion, String
subToolsetVersion, ProjectCollection projectCollection,
ProjectLoadSettings loadSettings) at
Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String
fileName, IDictionary2 globalProperties, String toolsVersion) at
OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Create(String
projectFilePath, String solutionDirectory, ILogger logger,
MSBuildOptions options, ICollection
1 diagnostics, Boolean
isUnityProject) at
OmniSharp.MSBuild.MSBuildProjectSystem.CreateProjectFileInfo(String
projectFilePath, Boolean isUnityProject)
知道这个问题的根源是什么吗?
我的环境是 Windows10,包括 VSCode 的 DotNet Core SDK 1.1.0、VSCode 1.12.2 和 Omnisharp 1.9.0 C# 扩展以及其他扩展。
项目是使用 dotnet core 命令创建的 "dotnet new mvc --auth Individual -o AM"。
OmniSharp 似乎加载了目前不支持 .NET Core 项目的 VS 2017 构建工具:https://github.com/Microsoft/msbuild/issues/1697。尝试安装具有 Web 开发/跨平台工作负载的 VS 2017 版本,或者在您的项目中创建一个 omnisharp.json
文件,其中包含:
{
"msbuild": {
"msbuildextensionspath": "C:\Program Files\dotnet\sdk\1.0.4\Sdks"
}
}
然后您需要通过命令行 dotnet restore
(因为构建工具也不包含 NuGet 版本)并在 VSCode.
中重新加载项目
我在制作 .NET core 3 项目时偶然发现了同样的问题,这对我有用。
我的 omnisharp.json 文件:
{
"MSBuild": {
"UseLegacySdkResolver": true
}
}
和我的 global.json(可选,通过 "dotnet --list-sdks" 检查您的 sdk 版本)
{
"sdk": {
"version": "3.0.100"
}
}
来源:https://github.com/OmniSharp/omnisharp-vscode/issues/3287#issuecomment-536180721
当我尝试在 visual studio 代码中打开 dotNet core 1.1 mvc 项目时,无法识别 csproj 文件,我无法从项目中获取任何符号。
VSCode 显示 "Some projects have trouble loading, please review the output for more details" 的 [警告] 消息。在输出中我收到以下消息:
[warn]: OmniSharp.MSBuild.MSBuildProjectSystem Failed to process project file 'c:\Users\humam\Projects\AM\AM.csproj'. c:\Users\humam\Projects\AM\AM.csproj(1,1) Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\MSBuild\Sdks\Microsoft.NET.Sdk.Web\Sdk\Sdk.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. c:\Users\humam\Projects\AM\AM.csproj at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(IElementLocation elementLocation, String resourceName, Object arg0) at Microsoft.Build.Evaluation.Evaluator
4.ExpandAndLoadImportsFromUnescapedImportExpression(String directoryOfImportingFile, ProjectImportElement importElement, String unescapedExpression, Boolean throwOnFileNotExistsError, List
1& imports) at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator
4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator
4.Evaluate() at Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary
2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary2 globalProperties, String toolsVersion) at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Create(String projectFilePath, String solutionDirectory, ILogger logger, MSBuildOptions options, ICollection
1 diagnostics, Boolean isUnityProject) at OmniSharp.MSBuild.MSBuildProjectSystem.CreateProjectFileInfo(String projectFilePath, Boolean isUnityProject)
知道这个问题的根源是什么吗?
我的环境是 Windows10,包括 VSCode 的 DotNet Core SDK 1.1.0、VSCode 1.12.2 和 Omnisharp 1.9.0 C# 扩展以及其他扩展。
项目是使用 dotnet core 命令创建的 "dotnet new mvc --auth Individual -o AM"。
OmniSharp 似乎加载了目前不支持 .NET Core 项目的 VS 2017 构建工具:https://github.com/Microsoft/msbuild/issues/1697。尝试安装具有 Web 开发/跨平台工作负载的 VS 2017 版本,或者在您的项目中创建一个 omnisharp.json
文件,其中包含:
{
"msbuild": {
"msbuildextensionspath": "C:\Program Files\dotnet\sdk\1.0.4\Sdks"
}
}
然后您需要通过命令行 dotnet restore
(因为构建工具也不包含 NuGet 版本)并在 VSCode.
我在制作 .NET core 3 项目时偶然发现了同样的问题,这对我有用。
我的 omnisharp.json 文件:
{
"MSBuild": {
"UseLegacySdkResolver": true
}
}
和我的 global.json(可选,通过 "dotnet --list-sdks" 检查您的 sdk 版本)
{
"sdk": {
"version": "3.0.100"
}
}
来源:https://github.com/OmniSharp/omnisharp-vscode/issues/3287#issuecomment-536180721