Arpit Srivastava
Arpit Srivastava

Reputation: 85

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

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.

Upvotes: 6

Views: 21556

Answers (3)

King
King

Reputation: 1

Could this be caused by copying the script to a new project? In the settings omnisharp is set to the latest version. The code doesn't seem broken in play mode, but in VS it is saying the UnityEngine.InputSystem is not recognized.

Upvotes: 0

xySVerma
xySVerma

Reputation: 971

For Mac, First you need to install following

  1. C# extension extension for Visual Studio COde
  2. Mono from https://mono-project.com/download/

Next, to resolve this issue, You need to edit Settings.json for visual studio code. It could be located via 2 methods

  1. Within Visual Studio Code -> Preferences -> Settings -> C# Configuration -> OmniSharp: Use Global Mono -> Edit in Settings.json.

  2. Browsing Mac File System Users -> -> Library -> Application Support -> Code -> User -> Settings.json

Finally, set the values in settings.json

{
    ...
    "omnisharp.useGlobalMono": "always"
    ...
}

In Rare scenario, if issue persists, you can set following too in addition to omnisharp.useGlobalMono

{
    ...
    "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current",
    "omnisharp.dotnetPath": ""
    ...
}

Upvotes: 2

iAM
iAM

Reputation: 1385

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

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

omnisharp path settings

  • 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.

Upvotes: 21

Related Questions