解決VS Code調試.NET Core應用遇到的坑


為什么會有”坑“

  博客園里有好多介紹怎么使用VS Code以及調試.NET Core的文章,但是都是基於直接構建Asp.Net Core Mvc單項目的,有什么區別呢!

  (1).我們這次遇到的坑是在多項目的解決方案中遇到的,也就是說根目錄不是一個項目的目錄;

  (2).DEBUG項目不能加載符號文件,導致項目不能斷點調試;

解決問題

  1.關於解決方案的目錄問題

  在launch.json中將 "program" 節點修改下:

  "program": "${workspaceRoot}”,workspaceRoot是解決方案目錄,修改這個值為"${workspaceRoot}/子項目目錄/bin/Debug/netcoreapp1.0/<項目名稱>.dll"

  修改后,DEBUG發現沒辦法Build, 提示 Couldn't find 'project.json' in current directory 。

  其實,原因是一樣的都是找不到項目目錄造成的,修改 tasks.json文件:

  為其添加一個options節點:

{ // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0", "command": "dotnet", "isShellCommand": true, "args": [], "options": { "cwd": "${workspaceRoot}/子項目目錄" }, "tasks": [ { "taskName": "build", "args": [ ], "isBuildCommand": true, "showOutput": "silent", "problemMatcher": "$msCompile" } ] }

 

  options的cwd節點,指定了dotnet命令行的工作目錄, 這樣修改后就可以正常build了

  2.關於DEBUG不能斷點調試

  查看LOG,發現DEBUG時會提示如下信息:

  Could not load symbols for '*.dll'. '*.pdb' is a Windows PDB. These are not supported by the cross-platform .NET Core debugger.

  大概的意思就是在windows下生成的符號文件,不能被跨平台的調試器加載。

  解決方案很簡單,在每個需要調試的項目文件(project.json)中,加入一個節點信息如下:

  "buildOptions": {
    "debugType": "portable"
  }
{ "version": "0.1.3-*", "buildOptions": { "debugType": "portable" }, "dependencies": { "Microsoft.AspNetCore.Http.Abstractions": "1.0.0", "Microsoft.AspNetCore.Owin": "1.0.0", "NETStandard.Library": "1.6.0", "YOYO.AspNetCore.Mvc": { "version": "0.1.3-*", "target": "project", "type": "build" }, "YOYO.AspNetCore.Owin": { "version": "0.1.3-*", "target": "project", "type": "build" }, "YOYO.Extensions.DI": "1.0.0-*" }, "frameworks": { "netstandard1.6": { "imports": "dnxcore50" }, "net451": { "dependencies": { "Owin": "1.0.0" } } } }
project.json

這是YOYOFx開源框架一個項目的project.json片段。

YOYOFx框架

GitHub:https://github.com/maxzhang1985/YOYOFx    Star下, 歡迎一起交流。

YOYOFx是一個輕量級用於構建基於 HTTP 的 Web 服務,基於 .NET 和 Mono 平台。

 .NET Core 和 YOYOFx 的交流群: 214741894 .NET Core跨平台 

 

如果你覺得本文對你有幫助,請點擊“推薦”,謝謝。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM