thangchung
thangchung

Reputation: 2030

How can we debug ASP.NET MVC web application in Visual Studio Code?

Microsoft just released Visual Studio Code a couple of days ago.

How can we debug an ASP.NET MVC applications from within that IDE?

Upvotes: 13

Views: 21574

Answers (4)

raddevus
raddevus

Reputation: 9077

Just saw the "Required assets to build and debug are missing from [project name]. Add them?" in Visual Studio Code

required assets missing

There should be a choice to display the "assets" it is talking about adding. These "assets" were added previously (yesterday when I created the project) and are only not showing up now because I've restarted my computer. It's a bit confusing.

If you click the gear icon on the right side,and then select the menu item (Manage Extension) that appears, then you'll see the asset it is talking about:

target asset shown

Here's the info on current version of Visual Studio Code and dependencies...

Visual Studio Code Version: 1.44.2
Commit: ff915844119ce9485abfe8aa9076ec76b5300ddd
Date: 2020-04-16T17:50:03.709Z
Electron: 7.1.11
Chrome: 78.0.3904.130 Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.3.0-51-generic

about Visual Studio code

Upvotes: 0

Shaun Luttin
Shaun Luttin

Reputation: 141434

Install the C# Extension

Open vscode and install the C# Extension.

  • CTRL + P
  • ext install csharp
  • Click Install.
  • After install, click Enable and restart vscode.

ext install csharp

Add launch.json and tasks.json

Open your project's directory in vscode. File > Open Folder...

Vscode might ask: Required assets to build and debug are missing from your project. Add them?

Required assets...

If so, choose Yes. This will add a .vscode directory with a launch.json and tasks.json file.

Note: If vscode does not ask this, you must ensure those files have the appropriate settings. One way to do that is to delete the existing .vscode directory and then restart vscode.

Debug

Open the Debug View (CTRL + SHIFT + D), choose a configuration, and click the green arrow. If you aren't sure which configuration to choose, use .NET Core Launch (web).

Debug view...

If you're setup properly, the web browser will open at localhost:5000 and the DEBUG CONSOLE will display output.

launch.json notes

This works for an EXE in net451.

"program": "${workspaceRoot}\\bin\\Debug\\net451\\myApp.exe",

This works for a DLL in netcoreapp1.0.

"program": "${workspaceRoot}\\bin\\Debug\\netcoreapp1.0\\myApp.dll",

program.json notes

Enable portable PDBs by adding the following entry. Otherwise you will receive the "No symbols have been loaded for this document" message.

"buildOptions: {
    "debugType": "portable",
}

See also

Upvotes: 16

Abhishek
Abhishek

Reputation: 7035

If you are using windows environment then you have to configure actions and add breakpoints, similar to visual studio and then use F5. See following image,

enter image description here

More info here

Upvotes: 2

MatteoSp
MatteoSp

Reputation: 3048

You can't (in this preview release). See: https://code.visualstudio.com/Docs/aspnet5

Upvotes: 1

Related Questions