在Visual Studio代码中使用C#

发布于 2025-02-08 06:04:26 字数 3111 浏览 4 评论 0原文

我是C#的新手,我似乎无法弄清楚我做错了什么。我正在用VS代码进行C#编码。起初,我只收到已经在代码中输入的关键字的代码建议。当试图修复它以建议我可以使用的任何关键字时,我认为我将更多地打破。现在,它建议更多的关键字,但是当我输入想要的内容(这不是一个建议)时,请按“。”,我现在写的内容会自动更改为顶级建议。我不确定我是否没有正确下载内容,但是我尝试多次卸载并重新安装.NET SDK,但没有运气,而VS代码中的C#扩展也相同。如果我打开一个终端,请单击输出并选择“无机”日志,我得到:

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#,并且不确定这些警告是什么意思(或者是否与我的原始问题有关)

I am new to C# and I can't seem to figure out what I did wrong. I was coding in C# on vs code. At first, I was only getting code suggestions for keywords that I had already typed into my code. When trying to fix it to suggest any keywords that I could use, I think I broke it more. It now suggests more keywords, but when I type in what I want (that isn't one of the suggestions) and press ".", what I have written now automatically changes to the top suggestion. I am not sure if I did not download things correctly, but I tried to uninstall and re-install .NET SDK multiple times with no luck, same with the C# extension in vs code. If I open a terminal, click on output and select OmniSharp Log, I get:

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.

Does this have to do with the code suggestions? I am not too familiar with OmniSharp, .NET, or C# and am not sure what these warnings mean (or if they are even related to my original problem)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知你几分 2025-02-15 06:04:26

您是单独打开文件吗?

对于.net,您需要正式创建一个项目(a .csproj文件)(尝试运行dotnet new -l <​​/code>查看各种可用的项目)。

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

Are you opening the file by itself?

For .NET you need to create a project (a .csproj file) normally (try running dotnet new -l to see all kinds of projects available).

This project needs its own folder, and then you add c# files to the same folder and its children.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文