11

I am using Visual Studio Code and I have already loaded C# OMNISharp plugin to my system and it works all fine in my existing project/solutions.

However, I just created a new solution and a new project in Visual Studio code and it sounds like for this particular solution, the Intellisense or any other Omnisharp features are just not working. I have tried following things:

  • Restarting Visual Studio Code
  • Disabling and enabling my OmniSharp Plug-in

Also, one thing that I noticed is that when a solution is created in Visual studio, it has a lot of code which looks like following:

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AEA16303-6991-4FF1-A3A9-72D892D7968C}"
EndProject

Basically, these are all project references. However, when a solution is created by Visual Studio Code then there is not any section like that. This solution runs and compiles fine, just that it looks fundamentally different than how a Visual Studio solution looks like.

However, nothing seems to be working. Is there anything that I can try to make it work? Any ideas ?

Lost
  • 12,007
  • 32
  • 121
  • 193
  • You should create your project with `dotnet new` (to target dotnet core) or with Visual Studio (to target the dot net framwork). The `Project` stuff you mention in your question is from the legacy csproj format generated by using the the latter. – caesay Jan 16 '18 at 20:54
  • Try disable or enable the C# extension – muhammad tayyab Mar 17 '19 at 05:13

8 Answers8

14

It's caused by adding *.sln and *.csproj to your "files.exclude" setting.

Try this:

Code -> Preferences -> Settings -> "omnisharp.useMono": true/false

Remove from setting file.

Or, Open your project with MonoDevelop or Visual Studio 2015/2017 first, then reopen VS-Code.


Edit 1: Try setting "omnisharp.useGlobalMono": never and then restarting the omnisharp server. Credit: The_Wolf and kao peter

  • 6
    Just put "Use global mono" to "never" and it worked. – The_Wolf Aug 23 '19 at 15:48
  • @The_Wolf I know that's old, but Use Global mono to never worked for me too. – ramires.cabral Sep 27 '19 at 21:44
  • I'm new to vs code. I don't understand how I can set `"omnisharp.useGlobalMono": never` . Where do I do that? Or how do I do `Code -> Preferences -> Settings -> "omnisharp.useMono": true/false` I expect it to mean that there is a menu called `Code` but I don't have a dropdown menu called `Code`. Where do I find `Code`? – patapouf_ai Aug 18 '22 at 21:46
6

How did you created the project? For the Intellisense to work properly the project needs to have a specific structure.

Assuming you have the .net core sdk for mac and the omnisharp extension installed:

Try the following:

  1. Open your integrated terminal (View => Integrated terminal)
  2. Create some new directory to host a test project say "testproj" e.g => mkdir testproj

  3. use the dotnet cli to initialize the project => dotnet new console

See if you got intellisense.
Also i'd recommend watching the .net core on Mac introduction video.

igorc
  • 2,024
  • 2
  • 17
  • 29
  • Ok so I think the only differentiator here was that you need to create the containing folder with MKDIR from console. You can not start doing `dotnet new` in an already existing project created by OS. Not sure why is that but sounds like that is the only way to make it work. – Lost Feb 09 '18 at 19:48
  • 1
    Did not work for me. VSCode refusing to give intellisense in one class in a new project whereas it works fine in other classes in other projects in the same solution – emirhosseini Mar 03 '20 at 17:39
4

In VS Code v1.43.2 adding following line to settings worked for me:

"omnisharp.useGlobalMono": "never"

The setting's value "never" had to be double-quoted otherwise it would be flagged in red. Even with the quotes, it remained highlighted in yellow. Not sure why, as all other options/values in there are blue. I presume this indicates some sort of warning, but it works.

(As an aside, I would love to understand what a "Globally installed mono" is. However my only interest here was getting IntelliSense working, so re: omnisharp I'm pleading 'newb'.)

Matt Ke
  • 3,599
  • 12
  • 30
  • 49
S M
  • 41
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/25895670) – Matt Ke Apr 19 '20 at 01:13
  • 1
    Actually it provides an improved answer as the original did not specify the required quotes. Forgive me for actually trying to learn something along the way, my mistake. – S M Apr 20 '20 at 13:35
  • Sorry, I missed that detail. I have restructured your answer to highlight the solution. (The comment you see above was created by the system when I reviewed your answer and marked it as "commentary".) – Matt Ke Apr 20 '20 at 23:58
  • This seems to work for me, but I have to add the setting to every new Unity project that I create, which is very annoying. Is there any other fix or some way to make this a "global" setting? – R1PFake Jul 22 '20 at 18:12
3

This worked for me

"omnisharp.useGlobalMono": "never"
Jon Martins
  • 65
  • 1
  • 4
1

Were your new solution and projects created in a "OneDrive" folder in Windows 10? In latest Windows 10 release, the C# plugin can't start up when a project resides in a OneDrive folder with "File On-Demand" feature on. Please take a look at this issue on Github

Ricky
  • 10,044
  • 3
  • 26
  • 31
1

I my case, the problem came from the resource folder of my project.

I had added a visual studio .sln file in the ressources to be used as a template but I somehow "variabilized" it with custom tags. OmniSharp tried to parse it and obviously failed, but no error poped up in VSCode, it was only visible in OmniSharp output.

The solution was to rename the template from .sln to .txt to prevent OmniSharp from loading it.

svyat1s
  • 868
  • 9
  • 12
  • 21
Poilaupat
  • 63
  • 1
  • 10
1

In my case, after installing C# extension, I had to click the setting icon on the extension and then click "Add to workspace recormendations"

Olawale david
  • 1,457
  • 1
  • 9
  • 13
1

I had this problem in 2022 and nothing mentioned above worked for me. For me the problem was caused by VS Code and C# plugin being updated (in my case c# plugin to v1.25.0+) because in this version they made this:

.NET Framework builds of OmniSharp no longer ship with Mono or the MSBuild tooling (See announcement omnisharp-roslyn#2339). To ensure that the C# > > extension remains usable out of the box for .NET SDK projects, we have > changed the default value of omnisharp.useModernNet to true.
If you still need Unity or .NET Framework support, you can set > omnisharp.useModernNet to false in your VS Code settings and restart OmniSharp.

So entier problem was in omnisharp.useModernNet being set to true by default which renders entire plugin unfunctional but doing what they said and setting omnisharp.useModernNet to false manually in .vscode > settings.json file solved this problem for me!
For more info, you can also read the entire official VS Code C# Plugin announcement under plugins Details section in VS Code or on this webpage as well!

Programer001
  • 31
  • 1
  • 6