vs code C# 扩展的问题,由于 OmniSharp,某些项目无法加载

Zey*_*ban 20 .net c# omnisharp visual-studio-code

当我开始编辑 C# 文件时,我收到此警告消息

Some projects have trouble loading. Please review the output for more details.
Run Code Online (Sandbox Code Playgroud)

我检查输出,这就是我发现的

Starting OmniSharp server at 2/17/2021, 6:06:51 AM
    Target: /Users/zeyad/Documents/Sandbox/CSharpTut

OmniSharp server started with Mono 6.12.0.
    Path: /Users/zeyad/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.7-beta.29/omnisharp/OmniSharp.exe
    PID: 1391

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 10.13.6 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Mono 16.6.0 - "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin"
            2: StandAlone 16.8.0 - "/Users/zeyad/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.7-beta.29/omnisharp/.msbuild/Current/Bin"
[warn]: OmniSharp.CompositionHostBuilder
        It looks like you have Mono installed which contains a MSBuild lower than 16.8.0 which is the minimum supported by the configured .NET Core Sdk.
 Try updating Mono to the latest stable or preview version to enable better .NET Core Sdk support.
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 16.6.0 - "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin"
            CscToolExe = csc.exe
            CscToolPath = /Users/zeyad/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.7-beta.29/omnisharp/.msbuild/Current/Bin/Roslyn
[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 '/Users/zeyad/Documents/Sandbox/CSharpTut'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        No solution files found in '/Users/zeyad/Documents/Sandbox/CSharpTut'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/zeyad/Documents/Sandbox/CSharpTut'.
[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 '/Users/zeyad/Documents/Sandbox/CSharpTut' on host 1365.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.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 '/Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj'.
/Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj
/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Microsoft.Common.CurrentVersion.targets(1193,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: /Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
        Solution initialized -> queue all documents for code analysis. Initial document count: 0.
Run Code Online (Sandbox Code Playgroud)

我检查了他们写的解决方案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).,它解决了问题,但第二天问题又出现了!

这是我在 settings.json 中添加的内容

"omnisharp.path": "latest",
"omnisharp.useGlobalMono": "always"
Run Code Online (Sandbox Code Playgroud)

我的 C# 扩展是 C# 扩展和 Roslynator。

为 C# 完全设置 Visual Studio 代码是否缺少某些内容?我对 C# 完全陌生,我真的很感激任何帮助,以获得与其他编程语言(如 JavaScript 或 Golang)相同的流畅感觉

注意:我使用 Mac,但这有什么区别吗?

小智 34

通过以下步骤修复该问题:

  1. 更新 Mono for Mac:https: //mono-project.com/download/
  2. VS Code > C# Enxtension(已安装)> 扩展设置 > 搜索:omnisharp.useGlobalMono':'always' > 将选项设置为“始终”

  • 安装**预览**版本后修复,而不是**稳定** (2认同)

小智 29

有两种方法可以解决这个问题。

第一个:检查你的 C# 扩展的版本。如果你是1.25.0,则需要到扩展设置中设置omnisharp.useModernNetfalse

第二:如果您使用的是 1.25.0 版本,请将版本恢复到 1.24.0。确保设置omnisharp.useGlobalMonoalways

  • 将“omnisharp.useModernNet”设置为“false”效果很好。我确实需要重新启动 vs-code 才能生效。 (4认同)
  • 这适用于 1.25.0!对于 Mac 用户 1) 转到用户文件夹并按 Cmd + Shift + 。显示隐藏的 Library 文件夹 2) 转到 `Library/Application Support/Code/User/settings.json` 3) 添加 `"omnisharp.useModernNet": false` 4) 重新启动 VS Code,您将在 C# 日志中看到它安装“OmniSharp for OSX (Mono / x64)” (2认同)

小智 16

这对我有用:

  1. 安装最新的 C# 扩展
  2. 安装最新的适用于 MAC 的 Mono:https ://mono-project.com/download/
  3. 更新 VSCode~/Library/Application Support/Code/User/settings.json如下:
   {
    ...
    "omnisharp.useGlobalMono": "always",
    "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current"
   }
Run Code Online (Sandbox Code Playgroud)

不需要"omnisharp.path": "latest",因为我不希望扩展程序每次都检查更新。


小智 11

对于那些来自最近时间范围的人来说只是一个提醒。Omnisharp 在其最新版本中弃用了 useGlobalMono 变量。我花了很多时间,但一旦我将 Omnisharp 恢复到1.24.0(从 1.25.0),一切就又开始工作了

  • 在 1.25.0 中,将omnisharp.useModernNet 设置为 false,正如 Airinfinite 在他的回答中提到的那样。 (3认同)