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
如果你想及时得到个人撰写文章以及著作的消息推送,或者想看看个人推荐的技术资料,可以扫描左边二维码(或者长按识别二维码)关注个人公众号(原来公众帐号 蒋金楠的自媒体将会停用)。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
相关文章
|
15天前
|
C# Windows
.NET开源免费的Windows快速文件搜索和应用程序启动器
今天大姚给大家分享一款.NET开源(MIT License)、免费、功能强大的Windows快速文件搜索和应用程序启动器:Flow Launcher。
|
15天前
|
存储 文字识别 C#
.NET开源免费、功能强大的 Windows 截图录屏神器
今天大姚给大家分享一款.NET开源免费(基于GPL3.0开源协议)、功能强大、简洁灵活的 Windows 截图、录屏、Gif动图制作神器:ShareX。
|
1月前
|
Windows
windows server 2019 安装NET Framework 3.5失败,提示:“安装一个或多个角色、角色服务或功能失败” 解决方案
windows server 2019 安装NET Framework 3.5失败,提示:“安装一个或多个角色、角色服务或功能失败” 解决方案
105 0
|
2月前
|
C# Windows
.NET开源的一个小而快并且功能强大的 Windows 动态桌面软件
.NET开源的一个小而快并且功能强大的 Windows 动态桌面软件
|
4月前
|
JavaScript Linux C#
【傻瓜级JS-DLL-WINCC-PLC交互】1.C#用windows窗体控件创建.net控件
【傻瓜级JS-DLL-WINCC-PLC交互】1.C#用windows窗体控件创建.net控件
65 0
|
4月前
|
人工智能 机器人 C#
Windows编程课设(C#)——基于WPF和.net的即时通讯系统(仿微信)
一款参考QQ、微信的即时通讯软件。采用CS结构,客户端基于.Net与WPF开发,服务端使用Java开发。
|
4月前
|
C# Windows
C#安装“Windows 窗体应用(.NET Framework)”
C#安装“Windows 窗体应用(.NET Framework)”
51 0
|
4月前
|
SQL Shell 数据库
七天.NET 8操作SQLite入门到实战 - 第二天 在 Windows 上配置 SQLite环境
七天.NET 8操作SQLite入门到实战 - 第二天 在 Windows 上配置 SQLite环境
|
4月前
|
缓存 C# Windows
一款.NET开源的小巧、智能、免费的Windows内存清理工具 - WinMemoryCleaner
一款.NET开源的小巧、智能、免费的Windows内存清理工具 - WinMemoryCleaner
|
5月前
|
JSON 监控 C#
10个基于.Net开发的Windows开源软件项目
10个基于.Net开发的Windows开源软件项目
44 0