简体   繁体   English

我们如何在 Visual Studio Code 中调试 ASP.NET MVC Web 应用程序?

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

Microsoft just released Visual Studio Code a couple of days ago.几天前,微软刚刚发布了Visual Studio Code

How can we debug an ASP.NET MVC applications from within that IDE?我们如何从该 IDE 中调试 ASP.NET MVC 应用程序?

Install the C# Extension安装 C# 扩展

Open vscode and install the C# Extension.打开 vscode 并安装 C# 扩展。

  • CTRL + P CTRL + P
  • ext install csharp
  • Click Install.单击安装。
  • After install, click Enable and restart vscode.安装完成后,点击启用并重启vscode。

分机安装 csharp

Add launch.json and tasks.json添加launch.json和tasks.json

Open your project's directory in vscode.在 vscode 中打开你的项目目录。 File > Open Folder...文件 > 打开文件夹...

Vscode might ask: Required assets to build and debug are missing from your project. Vscode 可能会问:您的项目中缺少构建和调试所需的资产。 Add them?添加它们?

所需资产...

If so, choose Yes .如果是,请选择Yes This will add a .vscode directory with a launch.json and tasks.json file.这将添加一个带有launch.jsontasks.json文件的.vscode目录。

Note: If vscode does not ask this, you must ensure those files have the appropriate settings.注意:如果 vscode 没有询问这个,你必须确保这些文件有适当的设置。 One way to do that is to delete the existing .vscode directory and then restart vscode.一种方法是删除现有的.vscode目录,然后重新启动 vscode。

Debug调试

Open the Debug View ( CTRL + SHIFT + D ), choose a configuration, and click the green arrow.打开调试视图 ( CTRL + SHIFT + D ),选择一个配置,然后单击绿色箭头。 If you aren't sure which configuration to choose, use .NET Core Launch (web).如果您不确定要选择哪种配置,请使用 .NET Core Launch (web)。

调试视图...

If you're setup properly, the web browser will open at localhost:5000 and the DEBUG CONSOLE will display output.如果设置正确,Web 浏览器将在 localhost:5000 处打开,并且 DEBUG CONSOLE 将显示输出。

launch.json notes launch.json 注释

This works for an EXE in net451 .这适用于net451的 EXE。

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

This works for a DLL in netcoreapp1.0 .这适用于netcoreapp1.0的 DLL。

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

program.json notes program.json 注释

Enable portable PDBs by adding the following entry.通过添加以下条目启用可移植 PDB。 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 .如果您使用的是windows 环境,那么您必须configure actions并添加断点,类似于 Visual Studio,然后使用F5 See following image,见下图,

在此处输入图片说明

More info here更多信息在这里

You can't (in this preview release).您不能(在此预览版本中)。 See: https://code.visualstudio.com/Docs/aspnet5请参阅: 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在 Visual Studio 代码中

所需资产缺失

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 和依赖项的信息...

Visual Studio Code Version: 1.44.2 Visual Studio 代码版本:1.44.2
Commit: ff915844119ce9485abfe8aa9076ec76b5300ddd提交:ff915844119ce9485abfe8aa9076ec76b5300ddd
Date: 2020-04-16T17:50:03.709Z日期:2020-04-16T17:50:03.709Z
Electron: 7.1.11电子:7.1.11
Chrome: 78.0.3904.130 Node.js: 12.8.1铬:78.0.3904.130 Node.js:12.8.1
V8: 7.8.279.23-electron.0 V8:7.8.279.23-electron.0
OS: Linux x64 5.3.0-51-generic操作系统:Linux x64 5.3.0-51-generic

关于 Visual Studio 代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 2019 中调试 ASP.Net MVC - How to debug ASP.Net MVC in Visual Studio 2019 使用 Visual Studio 代码创建 Asp.net MVC 应用程序(非核心) - Create Asp.net MVC Application (not core) with visual studio code 如何在Visual Studio社区2013中创建ASP.NET MVC 5 Web应用程序? - How to create ASP.NET MVC 5 Web Application in Visual Studio Community 2013? 如何使用.net 3.5在Visual Studio 2008,asp.net Web应用程序中生成QR码? - How to generate QR code in visual studio 2008,asp.net web application using .net 3.5? 无法调试在Visual Studio 2015上开发并托管在IIS上的asp.net Web应用程序 - Can't debug my asp.net web app developped on visual studio 2015 and hosted on IIS 在 VS Code 中使用实时预览调试 asp.net core mvc web 应用程序 - Debug asp.net core mvc web application with live preview in VS Code 在Visual Studio Code中调试多个ASP.NET Core项目 - Debug multiple ASP.NET Core projects in Visual Studio Code 如何在 C#、Visual Studio 2022 中的 NUnit 项目中运行 web 应用程序项目 (ASP.NET MVC) - How to run a web application project (ASP.NET MVC) within C#, NUnit project in Visual Studio 2022 在Web应用程序和Visual Studio for ASP.NET MVC上使用图像 - Using images on Web Applications and Visual Studio for ASP.NET MVC 如何在Visual Studio Code中调试ASP.NET网站? - How do I debug ASP.NET websites in Visual Studio Code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM