Unity: Omnisharp is not finding referenced projects in VSCode
Asked Answered
M

5

6

I recently upgraded to Unity 2019.3.0f6. When I opened one of my c# files, I noticed that UnityEngine.UI wasn't being recognized as a valid namespace. This caused me to get red squiggles whenever I referenced this namespace. IntelliSense also stopped working. This problem only shows up in VSCode, my project still runs just fine in Unity.

I checked the Omnisharp logs and found some errors that tell me Omnisharp is unable to find the UI .csproj file and a couple others.

[warn]: OmniSharp.MSBuild.ProjectLoader
    The referenced project 'UnityEngine.UI.csproj' does not exist.

What would cause this?

Things I've already tried:

  • Checking that the dotnet command works
  • Re-installing the c# vscode plugin
  • Deleting the .sln and .csproj files and letting Unity regenerate them
  • Re-installing Unity
Manthei answered 8/2, 2020 at 5:2 Comment(2)
Do you have the visual studio code package installed?Pancreas
@Pancreas Yes, I have the 2019.3 verified version of the package installed.Manthei
A
9

It is a bug in version 1.1.4 of Visual Studio Code Editor package.

These are the steps that I did to fix this issue:

  1. Open Window > Package Manager in Unity Editor
  2. Select Visual Studio Code Editor and click Remove
  3. Select "See all versions" under Visual Studio Code Editor
  4. Select version 1.1.3 and click Install
  5. Restart VS Code

There is a forum discussion on this here

And the actual issue is being worked on Unity Issue Tracker ticket here

UPDATE:

The current Visual Studio Code Editor package version 1.2.1 does not have this bug.

Adolf answered 4/3, 2020 at 8:21 Comment(6)
Thanks for your answer, I will check if this works for me soon and accept your answer if it does.Manthei
after trying to resolve that problem for 2 days....finally thank you bro....Di
thank you sooo much, I just wanted IntelliSense and now I can use it thank you!!!Izaak
Switched 1.1.3. Didn't work for me. Unity 2019.3.4f1. VS Code 1.43.0Eisteddfod
Downgraded to 1.1.3, solved the problem on Unity 2019.3.7f1Preserve
I managed to fix this by just updating the visual studio code reference from package manager. I didn't need to remove it.Edelsten
U
7

There is Assembly-CSharp.csproj file at the root of Unity project. I added this to fix error:

<Reference Include="UnityEngine.UI">
<HintPath>Library/ScriptAssemblies/UnityEngine.UI.dll</HintPath>
</Reference>
Urethritis answered 19/3, 2020 at 19:15 Comment(3)
this is the one solution that actually worked for me, the accepted solution didn't change anything. thanks!Odious
this actually fixed it for me, even using 1.2.2 Visual Studio Code Editor package was causing the issue.Clearly
Fixed it for me; Other references exist, but this generic one somehow does the trick...Stagestruck
E
4

In newer Versions of Unity this might still happen to you, and you may try these answers, but first make sure you have activated "Embedded Packages" and "Local Packages" at least in the Project settings if using VSCode and regenerate them; at least for me it made the errors due to missing Assemblies go away. Maybe for other issues you can try ticking others as well.

Of course my assemblies are set up correctly in Unity to reference each other. Just wanted to add this for those who maybe overlook that setting in search for a solution (I am pretty sure the original author already did this, but I see a few comments that hint me, that not everyone tried that first)

Enabled Sections in the Setup: Enabled Sections in the Setup

Enthrall answered 2/10, 2021 at 9:41 Comment(1)
It helped alot!Northeasterly
V
1

I'm having the exact same problem today. Didn't change anything. It just broke. I think the C# plugin in VSCode needs updated but I can't be sure. I'm fairly new to Unity but that seems to be the case. In the mean time I switched to VS2019 and it seems to be working. But I much prefer VSCode so I am looking for a solution too.

Varix answered 8/2, 2020 at 8:9 Comment(2)
Looks like this is the best option so far... :( Thanks for your solution!Manthei
It may be working again now. At least on my end it is. I loaded up my project this morning and everything seems to be fine.Varix
A
0

VSCode on a Mac. Problems with Omnisharp not loading. YouTube user Axiom. He explains how to fix Omnisharp loading. After I followed his video, It fixed my loading problem. The Fix. On your C# exstions under the gear pick "Extension Settings" then in the search bar add "useGlobalMono" - Under Use Global Mono - change "auto" to "always" and restart Omnisharp.

Video Reference - https://youtu.be/KJYrRv9cShY

Arleyne answered 9/11, 2021 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.