Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. In a .js file it works well and i'm guessing if there is some workaround this.

like image 635
Hiero De Paula Avatar asked Dec 27 '17 16:12

Hiero De Paula


People also ask

Does VS Code support C?

C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS.

How do you use C in visual code?

After stopping the C file, go & click the File button at the top left corner of the Visual Studio Code Editor, and select the Settings via Preferences, as shown below image. After clicking the Settings, it shows the image below. In this image, select the extension button to set the settings for the C Compiler.

Is C available in Visual Studio?

Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion.

Why is C not working in VS Code?

You have to change it so it runs in the terminal. Go to the menu Code > Preferences > Settings. In the User tab on the left panel, expand the Extensions section. Find and select Run Code Configuration.


2 Answers

There may be multiple "projects" in the folder and VSCode has selected the "wrong" one. (in VSCode terms "project" means the sln file)

Use ctrl-shift-P and select "OmniSharp: Select Project" to select the correct project (a .sln file).

If you have the Output window open with "OmniSharp Logs" selected, you will see it reading your csproj's. Once finished your goto definition will start to work

like image 98
AndyPook Avatar answered Sep 20 '22 06:09

AndyPook


As written in the comments for @AndyPook's answer, another possible solution is to just restart OmniSharp.

CTRL + SHIFT + P -> OmniSharp: Restart OmniSharp

like image 44
Yngvar Kristiansen Avatar answered Sep 22 '22 06:09

Yngvar Kristiansen