【问题标题】:c# Intellisense for unity is not working in vscodec# Intellisense for unity 在 vscode 中不起作用
【发布时间】:2022-01-07 09:32:07
【问题描述】:

我正在尝试让统一 Intellisense 在 vscode 中工作。 我正在使用:

- ubuntu 20.04
- unity 2020.3.23f1
- vscode 1.62.3 
- dotnet 6.0.100 
- mono 6.8.0.105

我在 vscode 中安装了 c# 扩展。

我设置: unity > 编辑 > 首选项 > 外部工具 > 外部脚本编辑器

到 /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

当我将 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 

我不知道这意味着什么或如何解决它,以便 Intellisense 能够正常工作。

【问题讨论】:

    标签: c# unity3d visual-studio-code intellisense


    【解决方案1】:

    尝试在External Tools 中单击regenerate project files。 ;)

    我使用 vscode 和插件: https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp https://marketplace.visualstudio.com/items?itemName=Unity.unity-debug

    而且效果很好。

    【讨论】:

    • :(它仍然在做同样的事情
    猜你喜欢
    • 2021-10-08
    • 2017-03-09
    • 2020-12-10
    • 1970-01-01
    • 2020-07-19
    • 2019-09-13
    • 1970-01-01
    • 2015-07-19
    • 2014-08-22
    相关资源
    最近更新 更多