How can we debug ASP.NET MVC web application in Visual Studio Code?
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.
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?
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).
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
- https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger.md
- https://code.visualstudio.com/Docs/editor/debugging
- https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp
You can't (in this preview release). See: https://code.visualstudio.com/Docs/aspnet5
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,
More info here