【问题标题】:Using c# in visual studio code在 Visual Studio 代码中使用 C#
【发布时间】:2022-10-19 14:56:59
【问题描述】:

我是 C# 新手,我似乎无法弄清楚我做错了什么。我在 vs 代码上用 C# 编码。起初,我只获得针对我已经在代码中输入的关键字的代码建议。当试图修复它以建议我可以使用的任何关键字时,我想我打破了它。它现在建议更多关键字,但是当我输入我想要的(这不是建议之一)并按“。”时,我现在写的内容会自动更改为最重要的建议。我不确定我是否没有正确下载东西,但我多次尝试卸载并重新安装 .NET SDK,但没有成功,与 vs 代码中的 C# 扩展相同。如果我打开一个终端,单击输出并选择 OmniSharp Log,我得到:

Starting OmniSharp server at 6/16/2022, 8:19:22 PM
    Target: c:\Users\joe4a\FlightSim\Scripts

OmniSharp server started with .NET 6.0.301
.
    Path: c:\Users\joe4a\.vscode\extensions\ms-dotnettools.csharp-1.25.0-win32-x64\.omnisharp\1.39.0-net6.0\OmniSharp.dll
    PID: 13892

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 10.0.19044.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: .NET Core SDK 6.0.301 17.2.0 - "C:\Program Files\dotnet\sdk\6.0.301\"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: .NET Core SDK 6.0.301 17.2.0 - "C:\Program Files\dotnet\sdk\6.0.301\"
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectSystem
        No solution files found in 'c:\Users\joe4a\FlightSim\Scripts'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'c:\Users\joe4a\FlightSim\Scripts'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Did not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location 'c:\Users\joe4a\FlightSim\Scripts' on host 2812.
[warn]: OmniSharp.Roslyn.CSharp.Services.InlayHints.InlayHintService
        Inlay hints requested for document not in workspace Location { FileName = c:\Users\joe4a\FlightSim\Scripts\AircraftRotaion.cs, Range = Range { Start = Point { Line = 0, Column = 0 }, End = Point { Line = 24, Column = 1 } } }
[warn]: OmniSharp.Roslyn.CSharp.Services.InlayHints.InlayHintService
        Inlay hints requested for document not in workspace Location { FileName = c:\Users\joe4a\FlightSim\Scripts\AircraftRotaion.cs, Range = Range { Start = Point { Line = 0, Column = 0 }, End = Point { Line = 24, Column = 1 } } }
[warn]: OmniSharp.Roslyn.CSharp.Services.InlayHints.InlayHintService
        Inlay hints requested for document not in workspace Location { FileName = c:\Users\joe4a\FlightSim\Scripts\AircraftRotaion.cs, Range = Range { Start = Point { Line = 0, Column = 0 }, End = Point { Line = 24, Column = 1 } } }
[info]: OmniSharp.OmniSharpWorkspace
        Miscellaneous file: c:\Users\joe4a\FlightSim\Scripts\AircraftRotaion.cs added to workspace
Received response for /v2/getcodeactions but could not find request.

这与代码建议有关吗?我对 OmniSharp、.NET 或 C# 不太熟悉,并且不确定这些警告的含义(或者它们是否与我最初的问题有关)

【问题讨论】:

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


    【解决方案1】:

    你是自己打开文件吗?

    对于 .NET,您需要正常创建一个项目(.csproj 文件)(尝试运行 dotnet new -l 以查看各种可用的项目)。

    该项目需要自己的文件夹,然后将 c# 文件添加到同一文件夹及其子文件夹中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-23
      • 2020-06-01
      • 1970-01-01
      • 2023-03-27
      • 2014-05-24
      • 1970-01-01
      • 2016-10-20
      • 1970-01-01
      相关资源
      最近更新 更多