Omnisharp-vscode: MSBuild does not locate targets for MonoGame

Created on 17 Apr 2017  路  30Comments  路  Source: OmniSharp/omnisharp-vscode

Environment data

dotnet --info output:

ambs@diabelli CourseCSharp $ dotnet --info
.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     linuxmint
 OS Version:  18.1
 OS Platform: Linux
 RID:         ubuntu.16.04-x64
 Base Path:   /usr/share/dotnet/sdk/1.0.1

VS Code version:
$ code --version
1.11.2
6eaebe3b9c70406d67c97779468c324a7a95db0e

C# Extension version: 1.8.1

Steps to reproduce

I open code with a standard C# hello world project, write 'Console.' and no completion is shown.

Expected behavior

Expected the list of available methods from the System.Console class

Actual behavior

none.

Bug Resolved-Fixed

Most helpful comment

Yup. OK. Here's a workaround for you. It's not great, but'll get your project working. Add an "omnisharp.json" file to the directory that you're opening in VS Code with the following content:

{
    "msbuild": {
        "MSBuildExtensionsPath": "/usr/lib/mono/xbuild"
    }
}

Be sure to keep that file in the root folder that you open in VS Code and it should get things working for you.

All 30 comments

Hi! Could you provide your OmniSharp Log after opening this project? To display the log, select View->Output to display the Output pane and select "OmniSharp Log" from the drop-down in the top-right corner of the pane.

Additionally, if you are using a different shell other than bash, could you let us know which one?

Just give me a couple hours to end $job, and I will give more details. Thanks!

Yes, I am using Bash.
I was trying to use code in two different ways:

  1. opening directly some .cs files that I have and compile manually
  2. opening a .csproj file

I do that, in both situations, from the command line: code file.cs / code file.csproj

In both situations, the output pane, has a dropdown with only two options, Tasks and Extensions, and both show an empty page.

Also, and this might be relevant, when doing 'code file.csproj' code opens the XML file and displays it :-O

Thanks

Would you be willing to provide the project you're using?

Note that we don't provide completion for loose .cs files outside of project.

OK for the loose .cs file. I was not sure, and therefore just mentioned it so you could clarify.

Not sure if you need the .csfile only, or everything, so I just uploaded my workdir here: http://eremita.di.uminho.pt/~ambs/TugEngine.tar.gz (it is a monogame project that compiles perfectly well with 'xbuild').

Thank you

OK. I've updated the title based on what I see on my Mac. I opened your solution and a .cs file. Then, I selected View-Output to display the VS Code Output pane and picked "OmniSharp Log" from the upper-right corner of the Output pane. In here, I see an exception like this:

Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/Users/dustincampbell/.vscode/extensions/ms-vscode.csharp-1.9.0-beta3/bin/omnisharp/msbuild/MonoGame/v3.0/MonoGame.Content.Builder.targets" was not found. Also, tried to find "MonoGame/v3.0/MonoGame.Content.Builder.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "/Library/Frameworks/Mono.framework/External/xbuild/" . These search paths are defined in "/Users/dustincampbell/.vscode/extensions/ms-vscode.csharp-1.9.0-beta3/bin/omnisharp/OmniSharp.exe.config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths.  /Users/dustincampbell/Downloads/TugEngine/TugEngine/TugEngine.csproj
  at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject (System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object[] args) [0x00067] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject (Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object[] args) [0x00001] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].ThrowForImportedProjectWithSearchPathsNotFound (Microsoft.Build.Evaluation.ProjectImportPathMatch searchPathMatch, Microsoft.Build.Construction.ProjectImportElement importElement) [0x000ae] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].ExpandAndLoadImports (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement) [0x0027f] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].EvaluateImportElement (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement) [0x00001] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].PerformDepthFirstPass (Microsoft.Build.Construction.ProjectRootElement currentProjectOrImport) [0x0036c] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].Evaluate () [0x00055] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].Evaluate (Microsoft.Build.Evaluation.IEvaluatorData`4[P,I,M,D] data, Microsoft.Build.Construction.ProjectRootElement root, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, System.Int32 maxNodeCount, Microsoft.Build.Collections.PropertyDictionary`1[T] environmentProperties, Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Evaluation.IItemFactory`2[S,T] itemFactory, Microsoft.Build.Evaluation.IToolsetProvider toolsetProvider, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, Microsoft.Build.Framework.BuildEventContext buildEventContext, Microsoft.Build.Execution.ProjectInstance projectInstanceIfAnyForDebuggerOnly) [0x0001a] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Evaluation.Project.Reevaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x0003c] in <6a1392588f4a45bdbe07807130f9b3d0>:0 
  at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00025] in <6a1392588f4a45bdbe07807130f9b3d0>:0 

Do you see something similar?

Out of curiosity, did this work for you in the past? Or, are you new to VS Code?

Scratch my comment about the exception. Once I installed MonoGame 3.6 on OSX, I see the project load properly and have IntelliSense working.

image

It never worked. I am new using Code (just migrated from Mac - Xamarin to Linux).
So, probably something failed during the installation of the plugin?
Thanks!

FWIW, I'm trying Ubuntu 16.04 now.

Hehehe, I imagine it works, as nobody else has complained. But I can't manage to get anything of it.

We'll see. I'm also using the latest beta of C# for VS Code

Is there a way to install the beta from code, directly?

I had to apt-get install gtk-sharp3 and MonoGame. After doing that, I can build your project with xbuild. However, I get the same error that I listed above. Do you see the same?

I do not see any error at all :-(

After opening the TugEngine folder and a .cs folder, you don't have an OmniSharp Log in View->Output?

ok, now I have some feedback

```````````````
Starting OmniSharp server at 4/18/2017, 6:05:13 PM
Target: /home/ambs/MyReps/TugEngine/TugEngine

OmniSharp server started wth Mono
Path: /home/ambs/.vscode/extensions/ms-vscode.csharp-1.9.0-beta3/bin/run
PID: 20674

OmniSharp: -s /home/ambs/MyReps/TugEngine/TugEngine --hostPID 20516 --stdio DotNet:enablePackageRestore=false --encoding utf-8 --loglevel information formattingOptions:useTabs=false formattingOptions:tabSize=4 formattingOptions:indentationSize=4
锘匡豢{"Event":"log","Body":{"LogLevel":"INFORMATION","Name":"OmniSharp.Startup","Message":"Omnisharp server running using Stdio at location '/home/ambs/MyReps/TugEngine/TugEngine' on host 20516."},"Seq":1,"Type":"event"}
Initializing in /home/ambs/MyReps/TugEngine/TugEngine
Auto package restore: False
Update workspace context
Resolving projects references
MSBUILD_EXE_PATH environment variable set to /home/ambs/.vscode/extensions/ms-vscode.csharp-1.9.0-beta3/bin/omnisharp/msbuild/MSBuild.dll
MSBuildExtensionsPath environment variable set to /home/ambs/.vscode/extensions/ms-vscode.csharp-1.9.0-beta3/bin/omnisharp/msbuild
MSBuildSDKsPath environment variable set to /home/ambs/.vscode/extensions/ms-vscode.csharp-1.9.0-beta3/bin/omnisharp/msbuild/Sdks
MSBuild will use local OmniSharp installation.
No solution files found in '/home/ambs/MyReps/TugEngine/TugEngine'
Failed to process project file '/home/ambs/MyReps/TugEngine/TugEngine/TugEngine.csproj'.
/home/ambs/MyReps/TugEngine/TugEngine/TugEngine.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/home/ambs/.vscode/extensions/ms-vscode.csharp-1.9.0-beta3/bin/omnisharp/msbuild/MonoGame/v3.0/MonoGame.Content.Builder.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. /home/ambs/MyReps/TugEngine/TugEngine/TugEngine.csproj
at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject (System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object[] args) [0x00067] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject (System.Boolean condition, System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object arg0) [0x0000a] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject (Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object arg0) [0x00001] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].ExpandAndLoadImportsFromUnescapedImportExpression (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, System.String unescapedExpression, System.Boolean throwOnFileNotExistsError, System.Collections.Generic.List1[Microsoft.Build.Construction.ProjectRootElement]& imports) [0x0041e] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].ExpandAndLoadImportsFromUnescapedImportExpressionConditioned (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, System.String unescapedExpression, System.Collections.Generic.List1[Microsoft.Build.Construction.ProjectRootElement]& projects, System.Boolean throwOnFileNotExistsError) [0x0005b] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].ExpandAndLoadImports (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement) [0x00033] in <6a1392588f4a45bdbe07807130f9b3d0>:0 at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].EvaluateImportElement (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement) [0x00001] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].PerformDepthFirstPass (Microsoft.Build.Construction.ProjectRootElement currentProjectOrImport) [0x0036c] in <6a1392588f4a45bdbe07807130f9b3d0>:0 at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].Evaluate () [0x00055] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Evaluation.Evaluator4[P,I,M,D].Evaluate (Microsoft.Build.Evaluation.IEvaluatorData4[P,I,M,D] data, Microsoft.Build.Construction.ProjectRootElement root, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, System.Int32 maxNodeCount, Microsoft.Build.Collections.PropertyDictionary1[T] environmentProperties, Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Evaluation.IItemFactory2[S,T] itemFactory, Microsoft.Build.Evaluation.IToolsetProvider toolsetProvider, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, Microsoft.Build.Framework.BuildEventContext buildEventContext, Microsoft.Build.Execution.ProjectInstance projectInstanceIfAnyForDebuggerOnly) [0x0001a] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Evaluation.Project.Reevaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x0003c] in <6a1392588f4a45bdbe07807130f9b3d0>:0
at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00025] in <6a1392588f4a45bdbe07807130f9b3d0>:0

    Detecting CSX files in '/home/ambs/MyReps/TugEngine/TugEngine'.
    Could not find any CSX files
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
    Configuration finished.

``````````````````````````

But still no completion :-)

Right. That exception above is the reason why. Essentially, it's not finding the MonoGame targets file that's installed. Once it fails to find that, it bails on processing the project further.

I think the problem so far was I was opening files and not folders (?).

So, vscode needs to find data about MonoGame but the installer did not place it in the correct place.

No, that's unlikely. MSBuild (and xbuild -- now deprecated) have... unconventional ways of locating files. It's more likely that we need to do something in OmniSharp to locate the targets properly.

ok, I can find that file here:
/usr/lib/mono/xbuild/MonoGame/v3.0/MonoGame.Content.Builder.targets

(msbuild or MSBuild -- command not found)

Yup. OK. Here's a workaround for you. It's not great, but'll get your project working. Add an "omnisharp.json" file to the directory that you're opening in VS Code with the following content:

{
    "msbuild": {
        "MSBuildExtensionsPath": "/usr/lib/mono/xbuild"
    }
}

Be sure to keep that file in the root folder that you open in VS Code and it should get things working for you.

Just great. Probably next versions can do that automatically
But for me this is fine :-) Thanks for your time!

Cool. We'll take a look at addressing this in OmniSharp soon. In the meantime, just adding that should fix it for any MonoGame project.

I would suggest keeping this around for reference while not fixed, but if you would like, be my guest closing it.

I've got a fix for this in PR here: https://github.com/OmniSharp/omnisharp-roslyn/pull/923. Once it's merged, it'll appear in C# for VS Code once we take a new version of OmniSharp.

I never realized this was a bug.... I've been constantly just recreating symlinks to folders that contain targets file... well my life is gonna get a whole lot easier :D

Was this page helpful?
0 / 5 - 0 ratings