vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Not working with Unity projects

Open rib opened this issue 6 years ago • 5 comments

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) info: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet info: OmniSharp.MSBuild.Discovery.MSBuildLocator 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" info: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Visual Studio Community 2019 16.5.30011.22 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin" info: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test'. info: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files info: OmniSharp.MSBuild.ProjectSystem Detecting projects in 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\grpc-unity-deadlock-reproduction.sln'. info: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp-firstpass.csproj' info: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp.csproj' info: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test'. info: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp-firstpass.csproj info: OmniSharp.Script.ScriptProjectSystem Could not find any CSX files info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 info: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 info: OmniSharp.WorkspaceInitializer Configuration finished. info: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test' on host 19800. info: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp-firstpass.csproj'. info: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp-firstpass.csproj' info: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp.csproj info: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp.csproj'. info: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\Robert\src\RealFit\unity-rust-plugin-test\Assembly-CSharp.csproj' info: OmniSharp.MSBuild.ProjectManager Update project: Assembly-CSharp-firstpass info: OmniSharp.MSBuild.ProjectManager Update project: Assembly-CSharp

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

rib avatar Nov 10 '20 02:11 rib

Please ensure that you have updated your VSCode Editor package in Unity to version 1.2.3. See the comments in this issue for more details - https://github.com/OmniSharp/omnisharp-vscode/issues/4113#issuecomment-718006809

filipw avatar Nov 10 '20 12:11 filipw

Ah, yep, sorry it looks like that's all I needed, thanks!

rib avatar Nov 10 '20 21:11 rib

thanks, I will close this then

filipw avatar Nov 11 '20 09:11 filipw

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. 😄

OsamaMSoliman avatar Dec 10 '21 01:12 OsamaMSoliman

@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 😄

jayscheidt avatar Dec 10 '21 14:12 jayscheidt