4

当我尝试在 Visual Studio 代码中打开 dotNet core 1.1 mvc 项目时,无法识别 csproj 文件,并且无法从项目中获取任何符号。

VSCode 显示 [warn] 消息“某些项目无法加载,请查看输出以获取更多详细信息”。在输出中,我收到以下消息:

[警告]:OmniSharp.MSBuild.MSBuildProjectSystem 无法处理项目文件“c:\Users\humam\Projects\AM\AM.csproj”。c:\Users\humam\Projects\AM\AM.csproj(1,1) Microsoft.Build.Exceptions.InvalidProjectFileException:导入的项目“C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\未找到 Sdks\Microsoft.NET.Sdk.Web\Sdk\Sdk.props”。确认声明中的路径正确,并且该文件存在于磁盘上。c:\Users\humam\Projects\AM\AM.csproj 在 Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) 在 Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject( IElementLocation elementLocation,字符串资源名称,4.ExpandAndLoadImportsFromUnescapedImportExpression(String directoryOfImportingFile, ProjectImportElement importElement, String unescapedExpression, Boolean throwOnFileNotExistsError, List1& 进口) 在 Microsoft.Build.Evaluation.Evaluator 4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) 在 Microsoft.Build.Evaluation.Evaluator 4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator4.Evaluate() 在 Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings ) 在 Microsoft.Build.Evaluation.Project.Initialize(IDictionary 2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings) 在 Microsoft.Build. Evaluation.ProjectCollection.LoadProject(字符串文件名,IDictionary2 globalProperties, String toolsVersion) at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Create(String projectFilePath, String solutionDirectory, ILogger logger, MSBuildOptions options, ICollectionOmniSharp.MSBuild.MSBuildProjectSystem.CreateProjectFileInfo(String projectFilePath, Boolean isUnityProject) 上的 1 个诊断,布尔 isUnityProject)

知道这个问题的根源是什么吗?

我的环境是 Windows 10,包括用于 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”创建的。

4

2 回答 2

2

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 中重新加载项目。

于 2017-05-16T11:08:34.517 回答
2

我在制作 .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

于 2019-10-01T16:58:37.840 回答