[英]VSCode C# "go to definition" (F12) not working
I'm using VSCode 1.19 and trying to "Go>Go to definition" in a C# file like in Visual Studio and it does nothing.我正在使用 VSCode 1.19 并尝试在 C# 文件中“转到>转到定义”,就像在 Visual Studio 中一样,它什么也没做。 In a.js file it works well and i'm guessing if there is some workaround this.在 a.js 文件中它运行良好,我猜是否有一些解决方法。
There may be multiple "projects" in the folder and VSCode has selected the "wrong" one.文件夹中可能有多个“项目”,而 VSCode 选择了“错误”的一个。 (in VSCode terms "project" means the sln file) (在 VSCode 术语中,“项目”是指 sln 文件)
Use ctrl-shift-P and select "OmniSharp: Select Project" to select the correct project (a .sln file).使用 ctrl-shift-P 并选择“OmniSharp:选择项目”以选择正确的项目(.sln 文件)。
If you have the Output window open with "OmniSharp Logs" selected, you will see it reading your csproj's.如果您打开输出窗口并选择“OmniSharp Logs”,您将看到它正在读取您的 csproj。 Once finished your goto definition will start to work完成后,您的 goto 定义将开始工作
As written in the comments for @AndyPook's answer, another possible solution is to just restart OmniSharp.正如@AndyPook 回答的评论中所写,另一种可能的解决方案是重新启动 OmniSharp。
CTRL + SHIFT + P -> OmniSharp: Restart OmniSharp
CTRL + SHIFT + P -> OmniSharp: Restart OmniSharp
"Go to definition" was working for me for a long time, but recently stopped working. “去定义”为我工作了很长时间,但最近停止工作。 My solution was:我的解决方案是:
Fix: When multiple solutions in same folder修复:当同一文件夹中有多个解决方案时
This answer is visual version of @AndyPook's answer.这个答案是@AndyPook 答案的可视化版本。
1. Crtl + Shift + P 1. Crtl加移+ P
2. Search >OmniSharp
2.搜索>OmniSharp
3. Choose option Select Project
3.选择选项Select Project
4. It will show all the list of solutions in your folder. 4.它将显示您文件夹中的所有解决方案列表。 select the correct eg:选择正确的例如:
5. Verify it by looking into OmniSharp Logs 5.通过查看 OmniSharp 日志来验证它
I had the same problem in VSCode (multiple projects Web API and Angular MVC) and resolved by creating a new sln
file.我在 VSCode(多个项目 Web API 和 Angular MVC)中遇到了同样的问题,并通过创建一个新的sln
文件来解决。 Please do the following steps:请执行以下步骤:
Step 1: Create the project sln
file.第一步:创建项目sln
文件。 ( ex: MyApp.sln
) (例如: MyApp.sln
)
Step 2: Open the sln
file and paste this code:第 2 步:打开sln
文件并粘贴以下代码:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyApp", "MyApp\MyApp.csproj", "{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Debug|x64.ActiveCfg = Debug|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Debug|x64.Build.0 = Debug|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Debug|x86.ActiveCfg = Debug|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Debug|x86.Build.0 = Debug|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Release|Any CPU.Build.0 = Release|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Release|x64.ActiveCfg = Release|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Release|x64.Build.0 = Release|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Release|x86.ActiveCfg = Release|Any CPU
{BC407A9C-4BD2-4086-9862-6E5A547D1DD8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Step 3: Crtl + Shift + P to switch on the project.第 3 步: Crtl + Shift + P打开项目。
I resolved by我解决了
OniSharp Error: Found dotnet version 5.0.201. OniSharp 错误:找到 dotnet 版本 5.0.201。 Minimum required version is 6.0.100 最低要求版本为 6.0.100
For anyone using the C# extension and coming here after May 24, 2022: version 1.25.0 of the extension disabled support for a few things对于使用 C# 扩展并在 2022 年 5 月 24 日之后来到这里的任何人:扩展的 1.25.0版禁用了对一些事情的支持
You can follow instructions at that link to get it working with 1.25.0, or you can rollback to version 1.24.4, per GeirS' answer根据GeirS 的回答,您可以按照该链接上的说明使其与 1.25.0 一起使用,或者您可以回滚到 1.24.4 版本
I had the same problem, but with a TypeScript project folder.我有同样的问题,但有一个 TypeScript 项目文件夹。 The solution was to simply reopen the folder.解决方案是简单地重新打开文件夹。
I know that I am late to this thread, but restarting omnisharp did not fix this problem for me.我知道我迟到了这个线程,但是重新启动 omnisharp 并没有为我解决这个问题。 What did fix the problem was running 'dotnet restore' and opening the project folder again.解决问题的是运行“dotnet restore”并再次打开项目文件夹。
PLUGGIN VSCODE "ANgular Language Service"插件VSCODE“角度语言服务”
Try Using Shift+Fn+F12 if all required extension are installed depends on your system config如果安装了所有必需的扩展,请尝试使用 Shift+Fn+F12 取决于您的系统配置
In my case, the answer by @Abdul Saboor sent me in the right direction.就我而言,@Abdul Saboor 的回答让我朝着正确的方向前进。 I checked the logs and it turns out the .NET 6 is required for this functionality.我检查了日志,结果发现此功能需要 .NET 6。
I face same probleam today, try to move my self from Visual Studiod to Code, As My porject is Microservie based , i have multiple Solution and repos with respect to each microservice , for make CI/CD simple, Now where the VS code Feature of Multipel Root Work Space helping me, So please follow below step if you are Setting up VS Code from professional developement prospect as c# developer,我今天面临同样的问题,尝试将我的自我从 Visual Studiod 转移到代码,因为我的项目是基于微服务的,对于每个微服务,我有多个解决方案和存储库,为了使 CI/CD 变得简单,现在 VS 代码功能Multipel Root Work Space 对我有帮助,所以如果您作为 c# 开发人员从专业开发前景设置 VS Code,请按照以下步骤操作,
Crtl+shif+P : Workspace:open Configuration file you can setup compound launch setting as well after that, to open multiple sln in debug mode at same time, like below one: "launch": { "configurations": [ Crtl+shif+P : Workspace:open 配置文件之后你也可以设置复合启动设置,在调试模式下同时打开多个sln,如下所示: "launch": { "configurations": [
], "compounds": [ { "name": "Launch Server & Client", "configurations": [ "CMSAPI",// Each indivisual sln launch setting unique name "Core" ] } ]
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.