作者:YOYOFx
連結:https://www.cnblogs.com/maxzhang1985/p/5682027.html
為什麼會有”坑“
部落格園裡有好多介紹怎麼使用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 
 
知識星球
朋友會在“發現-看一看”看到你“在看”的內容