How to debug .NET Core RC2 app with Visual Studio Code on Windows?

Simone Chiaretta (http://codeclimber.net.nz/archive/2016/05/20/How-to-debug-NET-Core-RC2-app-with-Visual-Studio.aspx)



So, you installed .NET Core RC2 , you followed the getting started tutorial
and you got your “Hello World!” printed on your command prompt just by
using the CLI. Then you went the next step and you tried to use Visual Studio Code and the C# extension
to edit the application outside of Visual Studio. And finally you want
to try and debug and set a breakpoint inside the application, but you
encountered some problems and nothing worked. Here is how to make it
work.

Specify the launch configuration

Visual
Studio Code needs to know how to launch your application, and this is
specified in alaunch.json file inside the .vscode folder. From the debug
window, click the “gear” icon and Code will create it for you: just
choose the right environment “.NET Core”.

Then you must specify the path to your executable in the program property. In the standard hwapp sample app, replace

   1: "program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",

with

   1: "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/hwapp.dll",

There is much more you can specify in the launch.json file. To see all the options have a look at the official doc: Debugging in Visual Studio Code.

Specify the task runner

If you try to debug now you’ll have another warning: “No task runner
configured”.This is because for launching, VS Code has to build the
project, and this is done via a task. But no worries, just click the
“Configure Task Runner” button in the info box, choose which task runner
you want to use, in this case “.NET Core”, and the tasks.json file will
be created for you. More info on task runners in VS Code can be found
on the offical documentation: Tasks in Visual Studio Code.

Running and debugging

Now you can click the “Start Debugging” button or F5 and the
application runs. Cool… Now you set a breakpoint and the executions
stops where you set it, doesn’t it? Well… if you are on Mac or Linux it
does. But it doesn’t stop if you are on Windows and the Debug Console
says something like:

   1: WARNING: Could not load symbols for 'hwapp.dll'.
   2: '...\hwapp\bin\Debug\netcoreapp1.0\hwapp.pdb' is a Windows PDB.
   3: These are not supported by the cross-platform .NET Core debugger.

Introducing Portable PDBs

In order to be able to debug cross-platform, .NET Core has now a “portable PDB” format,
and the newly introduced .NET Core debugger for Visual Studio Code only
supports this format. Unfortunately by default, on Windows, the .NET
Core build generates standard “Windows PDBs”, which are not supported.
But the fix is easy, you just have to tell the compiler to generate
portable PDBs.

This is done by specifying the debugType to be portable.

   1: {
   2:   "buildOptions": {
   3:     "debugType": "portable"
   4:   },
   5:   ...
   6: }

And voila! Breakpoints are hit!

作者:蒋金楠
微信公众账号:大内老A
微博:www.weibo.com/artech
如果你想及时得到个人撰写文章以及著作的消息推送,或者想看看个人推荐的技术资料,可以扫描左边二维码(或者长按识别二维码)关注个人公众号(原来公众帐号蒋金楠的自媒体将会停用)。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文链接

时间: 2024-10-29 00:44:10

How to debug .NET Core RC2 app with Visual Studio Code on Windows?的相关文章

【翻译】在Visual Studio中使用Asp.Net Core MVC创建你的第一个Web API应用(一)

HTTP is not just for serving up web pages. It's also a powerful platform for building APIs that expose services and data. HTTP is simple, flexible, and ubiquitous. Almost any platform that you can think of has an HTTP library, so HTTP services can re

Azure 部署 Asp.NET Core Web App

在云计算大行其道的时代,当你在部署一个网站时,第一选择肯定是各式各样的云端服务.那么究竟使用什么样的云端服务才能够以最快捷的方式部署一个 ASP.NET Core 的网站呢?Azure 的 Web App 服务是个很好的选择. 下面我们会通过 Visual Studio 创建一个 Asp.net Core demo 应用,然后把这个 demo 应用部署到 Azure Web App. 通过阅读本文,你将会了解到如何创建 Asp.NET Core 应用程序和如何在 Azure 上创建 Web Ap

Azure 上部署 ASP.NET Core Web App

前言 在云计算大行其道的时代,当你要部署一个网站时第一选择肯定是各式各样的云端服务.那么究竟使用什么样的云端服务才能够以最快捷的方式部署一个 ASP.NET Core的网站呢?Azure 的 Web App 服务是个很好的选择. 下面我们会通过 Visual Studio 创建一个 ASP.NET Core demo 应用,然后把这个 demo 应用部署到 Azure Web App.通过阅读本文,您将能了解到如何创建 Asp.NET Core 应用程序和如何在Azure上创建 Web App

Visual Studio 2015和 .NET Core安装教程_实用技巧

安装 Visual Studio 和 .NET Core 1.安装 Visual Studio Community 2015,选择 Community 下载并执行默认安装,Visual Studio 2015 安装程序首页 2.安装.NET Core + Visual Studio 工具,windows系统的可以从这里下载 创建 Web 应用程序 1.起始页 点击 新建项目(或 文件→新建→项目) 2.选择 左侧 .NET Core (如果没有安装.NET Core + Visual Studi

【dotnet跨平台】微软昨天宣布正式发布.NET Core RC2和.NET Core SDK Preview 1,还有Entity Framework Core RC2

 [dotnet跨平台]微软昨天宣布正式发布.NET Core RC2和.NET Core SDK Preview 1,还有Entity Framework Core RC2 期待已经的版本终于在昨天发布了 微软昨天宣布正式发布.NET Core RC2和.NET Core SDK Preview 1:https://blogs.msdn.microsoft.com/dotnet/2016/05/16/announcing-net-core-rc2/ 微软昨天宣布正式发布Entity Fra

【翻译】在Visual Studio中使用Asp.Net Core MVC创建第一个Web Api应用(二)

运行应用 In Visual Studio, press CTRL+F5 to launch the app. Visual Studio launches a browser and navigates to http://localhost:port/api/values, where port is a randomly chosen port number. If you're using Chrome, Edge or Firefox, the data will be display

【翻译】使用Visual Studio在Azure上部署Asp.Net Core Web应用

配置运行环境 Install the latest Azure SDK for Visual Studio. The SDK installs Visual Studio if you don't already have it. 安装Azure SDK for Visual Studio,如果你的Visual Studio还没有安装这个SDK的话 Install .NET Core + Visual Studio tooling 安装.NET Core + Visual Studio tool

visual studio 2010 debug问题

问题描述 visual studio 2010 debug问题 我在visual stdio 2010,在debug模式,不管运行什么程序都会出现这种错误,在release下就不会,就能运行 程序没错,不是程序的问题 解决方案 那就是vs2010的问题吧.重新安装一下

模式-关于visual studio里debug和release

问题描述 关于visual studio里debug和release 我的程序在debug模式下不能运行,但在release下能运行,这是哪儿配置错了吗 解决方案 代码能共享一下不?我也见识一下. 解决方案二: 不能运行,具体情况是什么呢?VS的什么错误的提示?先查一查两个模式工程设计的异同吧. 解决方案三: 把出错的log贴上来啊... 解决方案四: 我遇到的问题都是反过来的,还第一次听说你这种情况. 解决方案五: 先清理,再重编试试.