【问题标题】:vs code Problems with C# extension, Some projects have trouble loading due to OmniSharpvs 代码 C# 扩展问题,由于 OmniSharp,某些项目无法加载
【发布时间】:2021-02-17 04:12:49
【问题描述】:

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

Some projects have trouble loading. Please review the output for more details.

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

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.

我检查了他们写的解决方案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"

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

为 C# 完全设置 Visual Studio 代码是否缺少一些东西?我对 C# 完全陌生,如果能获得与其他编程语言(如 JavaScript 或 Golang)同样流畅的感觉,我将非常感谢任何帮助

注意:我使用的是 Mac,但这有什么不同吗?

【问题讨论】:

  • 听起来你需要更新 Mono
  • 我有 6.12.0.90 我认为是最新的,但我应该得到哪个包? Visual Studio 频道还是 Stable 频道?
  • 我不确定,因为我目前没有可以检查的 Mac,但上面的错误消息表明版本不匹配
  • 在我解决了这个错误之后,我得到了另一个错误,Visual Studio Code 现在将每一行都突出显示为错误,例如,using SystemThe type or namespace name 'System' could not be found 我尝试重新启动 OmniSharp 并尽我所能但是每当我修复错误时,我都会收到另一个错误,为什么我不能像其他语言一样用 C# 正常编码?我需要 Windows 而不是 Mac?我需要从 vs 代码迁移吗?
  • 它应该可以在 Mac 上正常工作。但是你需要问一个单独的问题,因为现在是不同的问题

标签: c# .net visual-studio-code omnisharp


【解决方案1】:

通过以下步骤解决此问题:

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

【讨论】:

  • 好建议。但它仍然没有修复。我将等待 OmniSharp 扩展的未来版本
  • 谢谢我在 ubuntu 20.4 上遇到了问题,这解决了。我正要回到Windows :(
  • 在安装 Preview 版本后修复,而不是 Stable
  • 老兄,我真的很爱你,感谢这个解决方案在新的 Macbook Pro Silicon 上运行良好!
【解决方案2】:

这对我有用:

  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"
   }

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

【讨论】:

  • 为我工作。谢谢@Ken
  • 非常感谢!作为一名来自完全不同技术的经验丰富的开发人员,您帮助我没有因为本应如此基本的东西而疯狂:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-05
  • 1970-01-01
相关资源
最近更新 更多