使用Visual Studio Code + ASP.NET 5 + Mono + Kestrel + OS X调试Web项目

Jac*_*ske 3 macos mono visual-studio-code kestrel-http-server asp.net-core

我是OS X的新手(使用我的新mac 4天了),我正在设置一个环境,我可以使用Visual Studio Code中内置的调试器在本地调试我的Asp.Net 5 Web项目,特别是获取附加到单声道时断点工作.

我按照这些说明安装了asp.net 5和visual studio代码.(http://docs.asp.net/en/latest/getting-started/installing-on-mac.html)

然后我安装了yeoman,并构建了一个aspnet项目.

我跑的命令dnu restore,dnu builddnx web.

该项目在Kestrel本地运行localhost:5000就好了.我也可以通过VS Code调试器将它附加到mono.

当我尝试在C#代码中设置断点时出现问题.调试器不会命中它们.

在做了一些研究后,我发现我需要将Startup.cs文件指定为mono作为要调试的文件.(https://code.visualstudio.com/Docs/editor/debugging)

但运行后mcs -debug Startup.cs,我得到这些错误:

Startup.cs(5,17): error CS0234: The type or namespace name `AspNet'     does not exist in the namespace `Microsoft'. Are you missing an assembly  reference?
Startup.cs(6,17): error CS0234: The type or namespace name `AspNet' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
Startup.cs(7,17): error CS0234: The type or namespace name `AspNet' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
Startup.cs(8,17): error CS0234: The type or namespace name `Data' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
Startup.cs(9,17): error CS0234: The type or namespace name `Extensions' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
Startup.cs(10,17): error CS0234: The type or namespace name `Extensions' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
Startup.cs(11,17): error CS0234: The type or namespace name `Extensions' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
Startup.cs(12,17): error CS0234: The type or namespace name `Extensions' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
Startup.cs(13,16): error CS0234: The type or namespace name `Models' does not exist in the namespace `palmtree'. Are you missing an assembly reference?
Startup.cs(14,16): error CS0234: The type or namespace name `Services' does not exist in the namespace `palmtree'. Are you missing an assembly reference?
Startup.cs(20,24): error CS0246: The type or namespace name `IHostingEnvironment' could not be found. Are you missing an assembly reference?
Startup.cs(20,49): error CS0246: The type or namespace name `IApplicationEnvironment' could not be found. Are you missing an assembly reference?
Startup.cs(39,16): error CS0246: The type or namespace name `IConfigurationRoot' could not be found. Are you missing an assembly reference?
Startup.cs(42,39): error CS0246: The type or namespace name `IServiceCollection' could not be found. Are you missing an assembly reference?
Startup.cs(62,31): error CS0246: The type or namespace name `IApplicationBuilder' could not be found. Are you missing an assembly reference?
Startup.cs(62,56): error CS0246: The type or namespace name `IHostingEnvironment' could not be found. Are you missing an assembly reference?
Startup.cs(62,81): error CS0246: The type or namespace name `ILoggerFactory' could not be found. Are you missing an assembly reference?
Run Code Online (Sandbox Code Playgroud)

看起来单声道无法正确调试编译Startup.cs.尝试设置调试时是否有其他人收到此错误?或者有没有人使用单声道,asp.net 5,红隼,代码和OS X的断点?

Sus*_*ver 6

调试Visual Studio代码和ASP.NET 5处于预览阶段,此时Visual Studio代码(在任何平台上)都不支持调试ASP.NET 5.请放心,我们正在努力在不久的将来为您带来这些体验.

参考:https://code.visualstudio.com/docs/runtimes/ASPnet5

您所指的Mono部分用于编译和附加到mono/.Net程序(不是基于ASP.NET的dnx程序).ASP.NET 5应用程序是使用Roslyn编译器编译的,而不是使用Mono编译的mcs.

调试单声道应用程序示例:

创建一个目录,cd进入它并键入code .以使用该目录启动VSCode.

mkdir monoconsoletest
cd monoconsoletest
code .
Run Code Online (Sandbox Code Playgroud)

在VSCode中创建一个新文件

在此输入图像描述

说出来 program.cs

在此输入图像描述

在编辑器中输入以下代码:

using System;

namespace consoleViaVSCode
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello VSCode!");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

你可以在shell中编译并运行它,但是让我们创建一个tasks.json文件,这样我们就可以通过它来完成Command Palette.

创建一个tasks.json文件:

下一步是设置任务配置.要执行此操作,请使用F1打开命令选项板,然后键入Configure Task Runner,按Enter键将其选中.

这将在.vscode文件夹中创建示例tasks.json文件.初始文件中包含大量示例.突出显示全部,删除它并添加:

{
    "version": "0.1.0",
    "command": "mcs",
    "isShellCommand": true,
    "showOutput": "silent",
    "args": ["-debug", "program.cs"]
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在你有一个任务可以通过task mcs向下执行Command Palette,这个任务将构建你program.cs使用Mono的mcs编译器和'-debug'选项,它将创建一个program.exe.mdb具有program.exe应用程序调试符号的文件.

因此,执行该任务,如果没有错误,program.exe将在文件窗格中显示a 和program.exe.mdb`:

在此输入图像描述

如果您有任何错误,它们将显示在Output窗格中(源代码窗格的右侧).

现在让我们添加一个taskmono.Net运行时运行你的程序,其中包含等待调试器附加的选项.

注意:我会告诉你一个mono debugger task但是在VSC 0.10.1中运行这样的shell进程.你会把它包裹在一个胶囊常规......: - /所以......

process.cs,Console.Write....在行上设置一个断点:

在此输入图像描述

从您启动VSCode的shell:

mono --debug --debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:5858 program.exe
Run Code Online (Sandbox Code Playgroud)

回到VSCode:

单击Bug IconConfig\Gear Icon然后选择"C#mono"以生成默认的"附加"配置.选择"附加",然后单击绿色"开始"按钮:

在此输入图像描述

你将达到你的断点:

在此输入图像描述