6

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.
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Arpit Srivastava
  • 85
  • 1
  • 1
  • 6
  • https://github.com/OmniSharp/omnisharp-vscode/issues/2937 – CodeCaster Jul 13 '19 at 10:34
  • So according to this thread it means that I need to either upgrade my Visual Studio to latest version i.e 2019 in order to make C# work on VS Code? or downgrade the .Net to a previous version if I want to continue using Visual Studio 2017? – Arpit Srivastava Jul 13 '19 at 11:25

3 Answers3

21

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.
iAM
  • 1,365
  • 15
  • 25
2

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": ""
    ...
}
xySVerma
  • 941
  • 9
  • 12
  • As the diagnostic output makes clear, neither Mac nor Mono is involved in this question. – Lance U. Matthews Apr 08 '22 at 05:51
  • 1
    I have mentioned mac because i am not aware of hierarchy in windows. If in windows, u need to look for appropriate option. Issue is configuration and its mentioned in detailed and it worked for me so i hope it will help someone else too. – xySVerma Apr 08 '22 at 08:59
0

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.

King
  • 1
  • 1
    Welcome to Stack Overflow! Please phrase this as an explained conditional answer, in order to avoid the impression of asking a clarification question instead of answering (for which a comment should be used instead of an answer, compare https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead ). For example like "If your problem is ... then the solution is to .... because .... ." – Yunnosch Oct 24 '22 at 19:32
  • please explain answer in respect of question for more detail refer guidlines – Pradeep Kumar Oct 26 '22 at 08:39