2

I am attempting to learn C#, and found the standard Ctrl+Alt+N does not work, and the tutorials online regarding building C# projects all seem to only mention using the command line with dotnet run. I have no problem with the command line, but it would greatly help my workflow if I didn't have to switch to mouse or trackpad to click the terminal and then back again.

  • See my answer here https://stackoverflow.com/questions/52786022/shortcut-for-running-terminal-command-in-vs-code/52786528#52786528 using `sendSequence` – Mark Sep 04 '19 at 20:24

3 Answers3

3

From the VS Code extensions Marketplace download and install the "terminal-command-keys" (by Pete Kinnecom) extension.

Open "keybindings.json" file (View > Command Palette > search for: " >preferences:Open Keyboard Shortcuts (JSON)"

In "keybindings.json" file put the following code inside the brackets "[]" :

{
    "key": "cmd+3",
    "command":"terminalCommandKeys.run",
    "args":{
        "cmd": "dotnet run"
    }

}

Save your "keybindings.json" file. (I have assigned "cmd + 3" key combination to "dotnet run" command. Use your own favorite key combination!

Notes:

  1. There is no space between cmd and + and 3 in the code.
  2. Pay attention to letter case of "terminalCommandKeys.run".
  3. Just to be sure, restart VS Code.

Source: Medium: Francis Mendez

Nader
  • 31
  • 5
  • This worked for me with a slight variation. I needed to run out of the folder of the active file, so i used `"cmd": "cd $(dirname \"${file}\") && dotnet run"` – MrMattSim Jul 07 '21 at 17:20
1

Not sure about VSCode, but in normal VS build is Shift+Ctrl+B

JBatstone
  • 167
  • 7
1

You can install an extension to help you with that. Here is some information: https://www.dotnetcurry.com/aspnet/1373/debugging-aspnet-core-using-visual-studio-code

Pedro Brito
  • 263
  • 1
  • 9