[英]c# Intellisense for unity is not working in vscode
I am trying to get unity Intellisense working in vscode.我正在尝试让统一 Intellisense 在 vscode 中工作。 I am using:
我在用:
- ubuntu 20.04
- unity 2020.3.23f1
- vscode 1.62.3
- dotnet 6.0.100
- mono 6.8.0.105
I installed the c# extension in vscode.我在 vscode 中安装了 c# 扩展。
I set: unity > edit > preferences > external tools >external script editor我设置:统一>编辑>首选项>外部工具>外部脚本编辑器
to /snap/bin/code when I open a script, it opens in vscode and gives me this: /snap/bin/code 当我打开一个脚本时,它会在 vscode 中打开并给我这个:
Starting OmniSharp server at 11/29/2021, 10:21:03 PM
Target: /home/(myusername)/Desktop/test/test.sln
OmniSharp server started.
Path: /home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/run
PID: 263330
[info]: OmniSharp.Stdio.Host
Starting OmniSharp on ubuntu 20.4 (x64)
[info]: OmniSharp.Services.DotNetCliService
Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 1 MSBuild instance(s)
1: StandAlone 17.0.0 - "/home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
MSBUILD_EXE_PATH environment variable set to '/home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: StandAlone 17.0.0 - "/home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin"
CscToolExe = csc.exe
MSBuildToolsPath = /home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin
CscToolPath = /home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin/Roslyn
BypassFrameworkInstallChecks = true
MSBuildExtensionsPath = /home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild
[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.Cake.CakeProjectSystem
Detecting Cake files in '/home/(myusername)/Desktop/test'.
[info]: OmniSharp.Cake.CakeProjectSystem
Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
Detecting projects in '/home/(myusername)/Desktop/test/test.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
Queue project update for '/home/(myusername)/Desktop/test/Assembly-CSharp.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in '/home/(myusername)/Desktop/test'.
[info]: OmniSharp.Script.ScriptProjectSystem
Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
Configuration finished.
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location '/home/(myusername)/Desktop/test' on host 263077.
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: /home/(myusername)/Desktop/test/Assembly-CSharp.csproj
[fail]: OmniSharp.MSBuild.ProjectLoader
This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. "omnisharp.useGlobalMono":"always" in C# Extension for VS Code).
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file '/home/(myusername)/Desktop/test/Assembly-CSharp.csproj'.
/home/(myusername)/Desktop/test/Assembly-CSharp.csproj
/home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1217,5): Error: This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. "omnisharp.useGlobalMono":"always" in C# Extension for VS Code).
[fail]: OmniSharp.MSBuild.ProjectManager
Attempted to update project that is not loaded: /home/(myusername)/Desktop/test/Assembly-CSharp.csproj
when I set omnisharp.useGlobalMono to always like it says to, I get this:当我将 omnisharp.useGlobalMono 设置为总是像它所说的那样时,我得到了这个:
Starting OmniSharp server at 11/29/2021, 10:29:27 PM
Target: /home/(myusername)/Desktop/test/test.sln
OmniSharp server started with Mono 6.8.0.
Path: /home/(myusername)/.vscode/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/OmniSharp.exe
PID: 263478
System.TypeLoadException: Could not load type of field 'McMaster.Extensions.CommandLineUtils.CommandLineApplication:_validationErrorHandler' (41) due to: Could not load file or assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
at OmniSharp.Stdio.StdioCommandLineApplication..ctor () [0x00000] in <fa42ddee3b094ad29621a886df38c746>:0
at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.<Main>b__0 () [0x00006] in <3fcd524b49434503b0223979f206dfcf>:0
at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <646769315b6548dcb5f6b23c2c2cc918>:0
I don't know what this means or how to fix it so Intellisense will work.我不知道这意味着什么或如何解决它,以便 Intellisense 可以工作。
Try to click regenerate project files
in External Tools
.尝试在
External Tools
中单击regenerate project files
。 ;) ;)
I use vscode and that plugins: https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp https://marketplace.visualstudio.com/items?itemName=Unity.unity-debug我使用 vscode 和插件: https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp https://marketplace.visualstudio.com/items?itemName=Unity.unity-debug
and it work nice.它工作得很好。
Often struggling with this... In my case (Mac OS) this happens when first opening VS Code directly from Unity, eg by double clicking on some C# script in the assets.经常为此苦苦挣扎......在我的情况下(Mac OS),当第一次直接从 Unity 打开 VS Code 时会发生这种情况,例如通过双击资产中的一些 C# 脚本。
Opening the VS Code application from the Finder solves for me (after OmniSharp finishes loading all project files).从 Finder 中打开 VS Code 应用程序为我解决了问题(在 OmniSharp 完成加载所有项目文件之后)。
Sometimes I also find useful calling OmniSharp: Select Project
and/or OmniSharp: Restart OmniSharp
from the VS Code Command Palette.有时我还发现调用
OmniSharp: Select Project
和/或OmniSharp: Restart OmniSharp
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.