Macos 调试带有Visual Studio代码的Web项目+;ASP.NET 5+;单声道+;红隼+;OSX

Macos 调试带有Visual Studio代码的Web项目+;ASP.NET 5+;单声道+;红隼+;OSX,macos,mono,asp.net-core,visual-studio-code,kestrel-http-server,Macos,Mono,Asp.net Core,Visual Studio Code,Kestrel Http Server,我对OSX非常陌生(使用我的新mac 4天),我正在建立一个环境,在那里我可以使用内置在Visual Studio代码中的调试器在本地调试Asp.NET5Web项目,特别是在连接到mono时让断点工作 我按照以下说明安装asp.net 5和visual studio代码。() 然后我安装了yeoman,并搭建了一个aspnet项目 我运行了命令dnu restore,dnu build,以及dnx-web 该项目在Kestrel上本地运行,本地主机:5000刚刚好。我还可以通过VS代码调试器将其

我对OSX非常陌生(使用我的新mac 4天),我正在建立一个环境,在那里我可以使用内置在Visual Studio代码中的调试器在本地调试Asp.NET5Web项目,特别是在连接到mono时让断点工作

我按照以下说明安装asp.net 5和visual studio代码。()

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

我运行了命令
dnu restore
dnu build
,以及
dnx-web

该项目在Kestrel上本地运行,本地主机:5000刚刚好。我还可以通过VS代码调试器将其连接到mono

当我试图在C代码中设置断点时,问题就出现了。调试器不会命中它们

在做了一些研究之后,我发现我需要将Startup.cs文件指定给mono作为要调试的文件。()

但是在运行了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?
看起来mono无法调试并正确编译Startup.cs。其他人在尝试设置调试时是否遇到此错误?或者有人在使用mono、asp.NET5、kestrel、vs代码和OSX时有断点吗

调试Visual Studio代码和ASP.NET 5处于预览状态,此时 Visual Studio代码(上)不支持时间调试ASP.NET 5 任何平台)。请放心,我们正在努力实现这些目标 在不久的将来,我将向你讲述我的经历

参考:

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

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

using System;

namespace consoleViaVSCode
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello VSCode!");
        }
    }
}
创建一个目录,将cd放入其中,然后键入
code.
以使用该目录启动VSCode

mkdir monoconsoletest
cd monoconsoletest
code .
在VSCode中创建新文件

将其命名为
program.cs

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

using System;

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

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

创建一个
tasks.json
文件:

using System;

namespace consoleViaVSCode
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello VSCode!");
        }
    }
}
下一步是设置任务配置。要执行此操作,请使用F1打开命令选项板并键入“配置任务运行程序”,然后按Enter键将其选中

这将在.vscode文件夹中创建一个示例tasks.json文件。初始文件中有大量示例。全部高亮显示、删除并添加:

{
    "version": "0.1.0",
    "command": "mcs",
    "isShellCommand": true,
    "showOutput": "silent",
    "args": ["-debug", "program.cs"]
}

现在,您有一个任务可以通过
命令面板下的
任务mcs
执行,该任务将使用Mono的mcs编译器和“-debug”选项构建
程序.cs
,该选项将创建一个
程序.exe.mdb
文件,其中包含
程序.exe
应用程序的调试符号

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

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

现在,让我们添加一个
任务
以使用
mono
.Net运行时运行程序,并提供等待调试器连接的选项

注意:我将向您展示一个
mono调试器任务
,但是在vsc0.10.1中运行这样的shell进程是不正确的。你会把它包装成一个忧郁的程序…:-/所以

进程.cs
中,在
控制台上设置断点。写入….
行:

using System;

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

从启动VSCode的shell:

mono --debug --debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:5858 program.exe
返回VSCode:

using System;

namespace consoleViaVSCode
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello VSCode!");
        }
    }
}
单击
Bug图标
,然后单击
Config\Gear图标
,然后选择“C#mono”以生成默认的“附加”配置。选择“附加”并单击绿色开始按钮:

您将到达断点:


注意:使用版本“1.0.0-rc1-final”有没有关于我最近没有在Ubuntu下尝试VSCode的想法,有点像是在等待所有不同的信息汇集在一起,形成一个完整的开发环境……只是现在没有时间调试开发工具,而不是为当前项目实际编写代码……:-/哈姆,我明白,看来调试需要更多的时间。我将尝试开始使用nGinx+Kestrel主机。半年过去了,有人知道调试ASP.NET Core 1.0(以前称为ASP.NET 5)现在是否在VS代码中受支持吗?这真的是一个非常重要的功能。@教授,你试过VSC1.1版吗?此外,还有许多调试器扩展可用@