简体   繁体   English

VSCode C#“转到定义”(F12)不起作用

[英]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:我的解决方案是:

  • Go to Extensions Go 到扩展
  • Find the C# extension (version 1.25.0 in my case)找到 C# 扩展(在我的例子中是 1.25.0 版)
  • Click the cogwheel点击齿轮
  • Select "Install Another Version..." Select“安装另一个版本...”
  • Select one of the previous versions (version 1.24.4 fixed the problem for me) Select 以前的版本之一(版本 1.24.4 为我解决了这个问题)
  • Press "Reload Required" when the selected version has been installed安装所选版本后按“需要重新加载”

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 日志来验证它

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我解决了

  1. check error on omnisharp log omnisharp log检查omnisharp日志上的错误omnisharp日志

OniSharp Error: Found dotnet version 5.0.201. OniSharp 错误:找到 dotnet 版本 5.0.201。 Minimum required version is 6.0.100 最低要求版本为 6.0.100

  1. set "omnisharp.useModernNet": false on C# extension user/workspace在 C# 扩展用户/工作空间上设置“omnisharp.useModernNet”:false

unchecked .net 6未选中 .net 6

  1. open source code folder and reload vscode打开源代码文件夹并重新加载 vscode

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“角度语言服务”

  1. Desisntalar ANGULAR SERVICE需求角度服务
  2. volver a instalar ANGULAR SERVICE volver 安装 ANGULAR SERVICE
  3. REINICIAR VISUAL-code REINICIAR VISUAL-代码

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,请按照以下步骤操作,

  • Install Node.js,安装 Node.js,
  • Install NPM.安装 NPM。
  • Install .net Core安装 .net 核心
  • Install git.(it can be other scm as well )安装git。(也可以是其他scm)
  • Now Install VS Code,现在安装 VS Code,
  • Install OMNI Sharp C# extension, this will help you in debug as well provide intllisence and provide feature like Go To Defination feature(it have one limittation at time it can run only on one solution even you have multi root workspace, I think they keep it like that way to keep the thing light weight ,to switch between multiple solution in such case you have to use switch project option.安装 OMNI Sharp C# 扩展,这将帮助您进行调试以及提供智能并提供诸如转到定义功能之类的功能(它有一个限制,即使您有多个根工作区,它也只能在一个解决方案上运行,我认为他们保留了它像这样保持东西轻量化,在这种情况下你必须使用切换项目选项在多个解决方案之间切换。 在此处输入图片说明 ) )
  • two more good extension i like is我喜欢的两个更好的扩展是
    • C# IDE(help you with few new nice template to create a Class File,Inferface option, the one i like is , when you create costructor and pull parameter show suggestion to create filed or proeperty for them just by Ctrl+.) C# IDE(用几个新的不错的模板来帮助你创建类文件,接口选项,我喜欢的是,当你创建 costructor 和拉参数时显示建议,只需按 Ctrl+ 即可为它们创建文件或属性。)
    • Git History to Check Git History. Git历史检查Git历史。
  • Multiple Teriminal is also nice feature as i have to run to many services at development time.多终端也是一个不错的功能,因为我必须在开发时运行许多服务。
  • You Can Setup launch.setting for each indivisual project required for debug(if donot want to do manually , first open each solution folder indivisually one by one, vsc help will create for you )您可以为调试所需的每个单独项目设置launch.setting(如果不想手动进行,请先单独打开每个解决方案文件夹,vsc帮助将为您创建)
  • To create WorkSpace, no need to do harwork just Start adding your sln folder to workspace tab,要创建工作区,无需做任何工作,只需开始将 sln 文件夹添加到工作区选项卡,
  • 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.

相关问题 当按F12进入Visual Studio 2015 / C#中的定义时出现错误 - I got error when press F12 Go to definition in Visual Studio 2015 / C# 当使用不同装配中的步骤定义时,转到定义(F12)不起作用 - Go To Definition (F12) not working when step definitions are used from a different assembly VSCode OSX C#,类未突出显示,无 ⌘ + F12 goto 实现 - VSCode OSX C#, classes not highlighted, no ⌘ + F12 goto implementation 如何隐藏<summary>在 Visual Studio 代码中按 F12(转到定义)时的 [元数据]</summary> - How to hide <summary> in [metadata] when press F12 (Go to definition) in visual studio code Visual Studio转到定义(F12)打开对象浏览器而不是代码视图 - Visual Studio Go to Definition (F12) opens Object Browser instead of Code View cmd(Telnet客户端)检测功能键(F1…F12)c# - cmd (telnet client) detect function keys (F1…F12) c# (函数,全局变量)之间的Visual Studio 2019脚本标记(在cshtml中)转到定义(F12)不起作用 - Visual Studio 2019 script tags (in cshtml) between (function,global variable) go to definition (F12) doesn't work Visual C# 在一天中的特定时间模拟 F12 按键 - Visual C# Simulating F12 keypress at certain time of day VS2010 C#:如何在按F12键时查看内部​​类的定义? - VS2010 C#: How to view internal classes definitions when I press F12? 如何使用F12在Visual Studio中查看C#代码详细信息? - How to see the c# code detail in visual studio using F12?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM