Visual Studio 代码 C# 扩展不工作

Visual Studio Code C# Extension not working

Windows 10 专业版 x64

几天来我一直在尝试解决这个问题,下载了多个不同版本的 .NET SDK,但我仍然从 C# 扩展中得到这个错误: “找不到 .NET Core SDK。将不会启用 .NET Core 调试。确保 .NET Core SDK 已安装并且在路径上。”

我去了那个帮助页面,它说在 cmd 提示符 window 中输入 where.exe,我照做了,收到了一个结果,然后返回到帮助页面,它说,“没有已知的原因导致 PATH 不会传播到 VS Code 进程。”

这是我的 OmniSharp 输出日志:

Starting OmniSharp server at 11/8/2021, 4:43:45 PM
    Target: c:\Users\eleph\Unity Projects\bEan\bEan.sln

OmniSharp server started.
    Path: c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\OmniSharp.exe
    PID: 15972

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (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 - "c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 17.0.0 - "c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin"
            CscToolExe = csc.exe
            CscToolPath = c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Roslyn
            MSBuildExtensionsPath = c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild
            MSBuildToolsPath = c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin
[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 'c:\Users\eleph\Unity Projects\bEan'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in 'c:\Users\eleph\Unity Projects\bEan\bEan.sln'.
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\UnityEngine.TestRunner.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.Timeline.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\UnityEngine.UI.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.TextMeshPro.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'c:\Users\eleph\Unity Projects\bEan\Assembly-CSharp.csproj'
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\UnityEditor.TestRunner.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.PlasticSCM.Editor.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\UnityEditor.UI.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.Services.Core.Editor.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.Timeline.Editor.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.TextMeshPro.Editor.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.CollabProxy.Editor.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.Rider.Editor.csproj
[warn]: OmniSharp.MSBuild.ProjectSystem
        Found project that doesn't exist on disk: c:\Users\eleph\Unity Projects\bEan\Unity.VSCode.Editor.csproj
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'c:\Users\eleph\Unity Projects\bEan'.
[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 'c:\Users\eleph\Unity Projects\bEan' on host 11172.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: c:\Users\eleph\Unity Projects\bEan\Assembly-CSharp.csproj
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'Unity.VSCode.Editor.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'Unity.TextMeshPro.Editor.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'Unity.Timeline.Editor.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'Unity.Timeline.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'Unity.TextMeshPro.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'UnityEditor.UI.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'Unity.PlasticSCM.Editor.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'Unity.Rider.Editor.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
        The referenced project 'UnityEngine.UI.csproj' does not exist.
[fail]: OmniSharp.MSBuild.ProjectLoader
        The reference assemblies for ".NETFramework,Version=v5.0.402" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK.
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file 'c:\Users\eleph\Unity Projects\bEan\Assembly-CSharp.csproj'.
c:\Users\eleph\Unity Projects\bEan\Assembly-CSharp.csproj
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'Unity.VSCode.Editor.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'Unity.TextMeshPro.Editor.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'Unity.Timeline.Editor.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'Unity.Timeline.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'Unity.TextMeshPro.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'UnityEditor.UI.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'Unity.PlasticSCM.Editor.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'Unity.Rider.Editor.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2068,5): Error: The referenced project 'UnityEngine.UI.csproj' does not exist.
c:\Users\eleph\.vscode\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp.37.16\.msbuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1217,5): Error: The reference assemblies for ".NETFramework,Version=v5.0.402" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK.

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: c:\Users\eleph\Unity Projects\bEan\Assembly-CSharp.csproj

作为参考,这是来自 Unity 项目的 C# 文件,但常规 C# 文件也不起作用。请帮忙,我目前在没有 IntelliSense 的情况下编程,也没有正确的语法突出显示,这让我抓狂。

切换到 VS,VSCode 与 VS 相比,Unity 支持并不多。