简体   繁体   中英

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?

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.

分机安装 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?

所需资产...

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

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

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

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

所需资产缺失

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:

显示的目标资产

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

关于 Visual Studio 代码

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM