VS Code 2017 - C# Error - “Some projects have trouble loading. Please review the output for more detail”

ε祈祈猫儿з 提交于 2020-12-06 10:57:30

问题


So I've installed the C# extension and .Net and everything else according to the tutorials on Internet, I have a workspace... and have done some other stuff like inputting some dotnet commands in terminal. Everything worked fine with no problem, but whenever I open the script/file... the one which is created initially - Program.cs which contains the default "Hello World!" program... then there it shows an error message that it was unable to load the project. Though, it outputs without any problem when I write dotnet run in terminal.

I've seen many threads like these on Internet, but nothing has worked for me yet. I just don't know what's going wrong. So that's why I'm asking this question here and putting the error message here... so that I can get to know what's going wrong in my case. As I'm new to VS Code... and don't know exactly whats going wrong.

Here's the error message which shows up in output tab -

Starting OmniSharp server at 13/7/2019, 3:46:46 PM
    Target: e:\CSharp Workspace

OmniSharp server started.
    Path: C:\Users\Arpit Srivastava\.vscode\extensions\ms-vscode.csharp-1.20.0\.omnisharp\1.32.20\OmniSharp.exe
    PID: 16516

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Visual Studio Community 2017 15.9.28307.222 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
            2: StandAlone 15.0 - "C:\Users\Arpit Srivastava\.vscode\extensions\ms-vscode.csharp-1.20.0\.omnisharp\1.32.20\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Visual Studio Community 2017 15.9.28307.222 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'e:\CSharp Workspace'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
        Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
        No solution files found in 'e:\CSharp Workspace'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'e:\CSharp Workspace\CSharp Workspace.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'e:\CSharp Workspace'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: e:\CSharp Workspace\CSharp Workspace.csproj
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location 'e:\CSharp Workspace' on host 7936.
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file 'e:\CSharp Workspace\CSharp Workspace.csproj'.
e:\CSharp Workspace\CSharp Workspace.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk' specified could not be found.  e:\CSharp Workspace\CSharp Workspace.csproj
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(ILoggingService loggingService, BuildEventContext buildEventContext)
   at Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at 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, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
   at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore(String filePath) in D:\a\1\s\src\OmniSharp.MSBuild\ProjectLoader.cs:line 129
   at OmniSharp.MSBuild.ProjectLoader.BuildProject(String filePath) in D:\a\1\s\src\OmniSharp.MSBuild\ProjectLoader.cs:line 72
   at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load(String filePath, ProjectIdInfo projectIdInfo, ProjectLoader loader) in D:\a\1\s\src\OmniSharp.MSBuild\ProjectFile\ProjectFileInfo.cs:line 94
   at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject(String projectFilePath, Func`1 loader) in D:\a\1\s\src\OmniSharp.MSBuild\ProjectManager.cs:line 304

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: e:\CSharp Workspace\CSharp Workspace.csproj

And instead if I try to run the program then I get this in the output -

scriptcs' is not recognized as an internal or external command,
operable program or batch file.

回答1:


To fix this set omnisharp.path in vs code settings to latest.

  • Go go settings -> Search foromnisharp.path -> click edit in settings.json

  • In the settings.json, scroll all the way down to the last settings add a comma then "omnisharp.path": "latest" -> save the file and restart vs code for the latest omnisharp(with the fix) to be installed.


来源:https://stackoverflow.com/questions/57018274/vs-code-2017-c-sharp-error-some-projects-have-trouble-loading-please-revie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!