question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working with Unity projects

See original GitHub issue

Issue Description

Steps to Reproduce

Omnisharp hasn’t been working in VS Code with Unity projects for me for several weeks now (was just burying my head in the sand hoping it was a temporary issue but it doesn’t look like it). It’s affecting multiple Unity projects (all that I’ve tried) for me that used to be supported fine, so I guess there’s been a vscode / omnisharp update that’s changed something - I’m not really sure.

Expected Behavior

When looking at code that compiles in Unity there shouldn’t be lots of compilation errors highlighted.

Actual Behavior

Code that’s known to compile (compiles fine within Unity itself) is showing lots of errors (namely with using some third-party plugins that are copied into the project.

I’ve tried changing my preferences in Unity to make sure it generates csproj file for everything and triggered it to regenerate all projects but don’t see any difference from doing that.

Logs

OmniSharp log

Starting OmniSharp server at 10/11/2020, 01:55:52 Target: c:\Users\Robert\src\RealFit\unity-rust-plugin-test\grpc-unity-deadlock-reproduction.sln

OmniSharp server started. Path: c:\Users\Robert.vscode\extensions\ms-dotnettools.csharp-1.23.5.omnisharp\1.37.3\OmniSharp.exe PID: 10404

    Starting OmniSharp on Windows 6.2.9200.0 (x64)
    DotNetPath set to dotnet
    Located 3 MSBuild instance(s)
        1: Visual Studio Community 2019 16.5.30011.22 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"
        2: Visual Studio Build Tools 2019 16.5.30011.22 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
        3: StandAlone 16.8.0 - "c:\Users\Robert\.vscode\extensions\ms-dotnettools.csharp-1.23.5\.omnisharp\1.37.3\.msbuild\Current\Bin"
    Registered MSBuild instance: Visual Studio Community 2019 16.5.30011.22 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin"
    Detecting Cake files in 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test'.
    Could not find any Cake files
    Detecting projects in 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\grpc-unity-deadlock-reproduction.sln'.
    Queue project update for 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp-firstpass.csproj'
    Queue project update for 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp.csproj'
    Detecting CSX files in 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test'.
    Loading project: c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp-firstpass.csproj
    Could not find any CSX files
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
    Configuration finished.
    Omnisharp server running using Stdio at location 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test' on host 19800.
    Successfully loaded project file 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp-firstpass.csproj'.
    Adding project 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp-firstpass.csproj'
    Loading project: c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp.csproj
    Successfully loaded project file 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp.csproj'.
    Adding project 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp.csproj'
    Update project: Assembly-CSharp-firstpass
    Update project: Assembly-CSharp</details>

C# log

The ‘C#’ log tab is empty in VS Code

Here’s just one example of the kind of error I’m seeing in my code because it’s not handling the project’s dependency on a UniTask plugin that’s embedded in the project…

At the top of the file where there’s an appropriate using directive like using Cysharp.Threading.Tasks; which should bring in the UniTask type I get this error:

The type or namespace name 'Cysharp' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp, Assembly-CSharp]

The later when referring to the UniTask type I see:

The type or namespace name 'UniTask<>' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]

For reference UniTask is from here: https://github.com/Cysharp/UniTask

Environment information

VSCode version: 1.51.0 C# Extension: 1.23.5 Unity: 2019.4…14f1

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.201 Commit: b1768b4ae7

Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.201\

Host (useful for support): Version: 3.1.3 Commit: 4a9f85e9f8

.NET Core SDKs installed: 2.1.801 [C:\Program Files\dotnet\sdk] 2.2.109 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk] 3.1.201 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
auto-rename-tag formulahendry 0.1.5
code-settings-sync Shan 3.4.3
code-spell-checker streetsidesoftware 1.9.3
cpptools ms-vscode 1.1.0
csharp ms-dotnettools 1.23.5
flatbuffers gaborv 0.1.0
gitlab-workflow GitLab 3.6.0
html-tag-wrapper hwencc 0.2.3
npm-intellisense christian-kohler 1.3.1
python ms-python 2020.10.332292344
remote-ssh ms-vscode-remote 0.55.0
remote-ssh-edit ms-vscode-remote 0.55.0
remote-wsl ms-vscode-remote 0.51.2
rust rust-lang 0.7.8
rust-analyzer matklad 0.2.376
serverless-ide-vscode ThreadHeap 0.5.26
shopify-liquid sissel 2.3.0
Theme-MarkdownKit ms-vscode 0.1.4
vim vscodevim 1.17.1
vscode-eslint dbaeumer 2.1.13
vscode-npm-script eg2 0.3.13
vscode-proto3 zxh404 0.5.2
xml DotJoshJohnson 2.5.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
OsamaMSolimancommented, Dec 10, 2021

I had the exact same Problem with UniTask (last version)

  • VSCode Editor package in Unity to version: 1.2.4
  • VSCode version: 1.63.0
  • C# Extension: 1.23.17
  • Unity: 2020.3.21f1

the idea is how to force VSCode to check again for Assembly references (as they are added and Unity sees them, i.e. no errors are shown on Unity’s side), solution was to

delete all .sln and .csproj files from the root of the Unity project and restart the editor.

and this did the trick 😉 .

it took me a sometime to figure that out, hope that helps, if anyone came later looking for a solution. 😄

7reactions
jayscheidtcommented, Dec 10, 2021

@OsamaMSoliman Thanks for the help! Instead of deleting all the files, I found success reloading the *.csproj files from Unity

  1. Go to Unity -> Edit -> Preferences -> External Tools
  2. Look for the section near the top called Generate .csproj files for: and click Regenerate Project Files with everything unchecked.
  3. Then in VSCode Ctrl + Shift + P and run Developer: Reload Window

Now UniTask has intellisense 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unity Won't Open ANY Project
Unity Won't Open ANY Project · 1.Open Unity Hub · 2.Open Preferences/settings menu · 3.Click On licenses · 4.Return Personal License · 5.Re-ADD ......
Read more >
How to fix Unity hub not opening unity project when clicked?
Delete Unity Hub and open the project through Unity. Otherwise, if you are using crack, try to completely delete ...
Read more >
Troubleshooting - Unity - Manual
Troubleshooting · Error messages in the Package Manager window · Package Manager missing or window doesn't open · Problems after upgrading Unity to...
Read more >
Troubleshooting and known issues (VS Tools for Unity)
Incompatible project in Visual Studio · Check that Visual Studio is set as your external script editor in Unity using Edit / Preferences...
Read more >
Unity Project Not Opening - Ask - GameDev.tv Community
And if it still does not work, try to open the project, wait a few seconds, then press ctrl + shift + esc...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found