Levi J
Levi J

Reputation: 95

Unity: Omnisharp is not finding referenced projects in VSCode

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:

Upvotes: 6

Views: 13093

Answers (5)

David
David

Reputation: 11

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

Upvotes: 0

g4borg
g4borg

Reputation: 106

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

Upvotes: 4

Timo Salokas
Timo Salokas

Reputation: 136

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.

Upvotes: 9

Damjan Pavlica
Damjan Pavlica

Reputation: 34123

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>

Upvotes: 7

Lee Robison
Lee Robison

Reputation: 39

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.

Upvotes: 2

Related Questions