【问题标题】:Visual Studio Code debugging the default ASP.NET Core MVC WebApp: does not workVisual Studio Code 调试默认 ASP.NET Core MVC WebApp:不起作用
【发布时间】:2019-06-27 02:26:12
【问题描述】:

我正在使用 Manjaro linux 并尝试调试默认的 ASP.NET Core MVC 项目,但调试停止,没有任何错误

我在Meow 文件夹中使用dotnet new mvc 创建了项目,没什么特别的,然后添加了一个新配置.NET Core Launch (web)

事实证明,在tasks.json 中定义的build 任务中只调用了dotnet build,正如在launch.jsonpreLaunchTask 中定义的那样,这就是调试过程开始和停止而没有显示任何错误。

运行 dotnet run 时,一切正常,所以我怀疑问题更多来自我的 Visual Studio 调试配置。

在终端标签中我有:

> Executing task: dotnet build /home/perret/Desktop/Playground/CSharpmusement/Meow/Meow.csproj <

Microsoft (R) Build Engine version 15.9.20.63311 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 86.18 ms for /home/perret/Desktop/Playground/CSharpmusement/Meow/Meow.csproj.
  Meow -> /home/perret/Desktop/Playground/CSharpmusement/Meow/bin/Debug/netcoreapp2.2/Meow.dll
  Meow -> /home/perret/Desktop/Playground/CSharpmusement/Meow/bin/Debug/netcoreapp2.2/Meow.Views.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.62

Terminal will be reused by tasks, press any key to close it.

下面两个自动生成的文件看起来不错。

launch.json

{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
   "version": "0.2.0",
   "configurations": [
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/Meow.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "launchBrowser": {
                "enabled": true,
                "args": "${auto-detect-url}",
                "windows": {
                    "command": "cmd.exe",
                    "args": "/C start ${auto-detect-url}"
                },
                "osx": {
                    "command": "open"
                },
                "linux": {
                    "command": "xdg-open"
                }
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ,]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/Meow.csproj"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

[更新 1]

尝试卸载omnisharp并重新安装(中间有VSCode重启):

Starting OmniSharp server at 2/3/2019, 11:19:16 AM
    Target: /home/perret/Desktop/Playground/CSharpmusement/Meow

OmniSharp server started with Mono 5.16.0.
    Path: /home/perret/.vscode-oss/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/OmniSharp.exe
    PID: 21990

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on manjaro 0.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Mono 15.0 - "/usr/lib/mono/msbuild/15.0/bin"
            2: StandAlone 15.0 - "/home/perret/.vscode-oss/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild/15.0/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 15.0 - "/usr/lib/mono/msbuild/15.0/bin"
            CscToolPath = /home/perret/.vscode-oss/extensions/ms-vscode.csharp-1.17.1/.omnisharp/1.32.8/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/home/perret/Desktop/Playground/CSharpmusement/Meow'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
        Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
        No solution files found in '/home/perret/Desktop/Playground/CSharpmusement/Meow'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/home/perret/Desktop/Playground/CSharpmusement/Meow/Meow.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/home/perret/Desktop/Playground/CSharpmusement/Meow'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/home/perret/Desktop/Playground/CSharpmusement/Meow' on host 21903.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /home/perret/Desktop/Playground/CSharpmusement/Meow/Meow.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/home/perret/Desktop/Playground/CSharpmusement/Meow/Meow.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/home/perret/Desktop/Playground/CSharpmusement/Meow/Meow.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Meow

[更新 2]

调试器安装正确(我尝试全新安装):

Installing C# dependencies...
Platform: linux, x86_64, name=manjaro, version=unknown

Downloading package 'OmniSharp for Linux (x64)' (30903 KB).................... Done!
Installing package 'OmniSharp for Linux (x64)'

Downloading package '.NET Core Debugger (linux / x64)' (59407 KB).................... Done!
Installing package '.NET Core Debugger (linux / x64)'

Downloading package 'Razor Language Server (Linux / x64)' (44979 KB).................... Done!
Installing package 'Razor Language Server (Linux / x64)'

Finished

Also filed an issue on Github.

【问题讨论】:

  • 您确定 C# 扩展已正确安装 .NET Core 调试器吗?
  • @LexLi 我认为是这样(Omnisharp 选项卡在启动和检查项目时没有显示任何错误)。此外,调试一个简单的控制台应用程序似乎也无缘无故停止了。
  • 重新安装扩展,它应该尝试再次下载调试器。确保网络允许外部下载。
  • @LexLi 我更新了我的帖子,显示了 Omnisharp 日志。调试器已经设置好了。
  • Microsoft .NET Core 调试器不是开源的,它对 Linux 发行版的支持应该非常有限。我不认为 OmniSharp 的人可以在这方面提供帮助,但您可能会看到他们所说的。

标签: c# debugging asp.net-core visual-studio-code .net-core


【解决方案1】:

我在这些 GitHub 问题上回答了我自己的问题:

我在新的 Manjaro Gnome 变体实时会话中的解决方案的基本步骤:

  • 安装 ~~yay 即可享受 AUR 而无需在命令行中挣扎:sudo pacman -Sy yay~~yay -S dotnet-sdk mono binutils msbuild-stable visual-studio-code-bin --noconfirm(请参阅下面的 [更新])。

  • 设置您需要的一切(也称为 .NET Core SDK、Mono、MSBuild 和 Visual Studio Code Insiders):yay -S dotnet-sdk mono binutils msbuild-stable visual-studio-code-insiders --noconfirm

    • 注意:binutils 导致 Gnome 变体似乎没有在本机嵌入该变体,这需要在 msbuild-stable 安装的步骤之一中进行剥离。
  • 在您的主文件夹中的.bashrc 文件末尾添加您要导出的所需环境变量:

    • export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
    • export PATH="$PATH:/home/manjaro/.dotnet/tools"
  • 创建一个虚拟项目:dotnet new mvc

  • 启动 Visual Studio Code Insiders:code-insiders .

  • 安装 C# 扩展 CTRL + SHIFT + P ext install ms-vscode.csharp

  • 下载 C# 扩展的 .NET 代码调试器(如果需要/第一次尚未完成) CTRL + SHIFT + P Debug: Download .NET Core Debugger

  • 生成 launch.jsontasks.json 文件(如果尚未对弹出窗口回答“是”:“您想添加所需的资产来构建和调试您的项目吗?”) CTRL + SHIFT + P .NET: Generate Assets for Build and Debug

  • 安装开发自签名证书的工具 dotnet tool install --global dotnet-dev-certs

  • 注册开发自签名证书: dotnet dev-certs https

  • 调试 (.NET Core Launch (web)) CTRL + SHIFT + D F5

虽然这并不稳定,正如我最初帖子中的一位 cmet 指出的那样,Arch / Manjaro 不受调试器的官方支持,但我发现这与 Visual Studio Code 的版本更相关,atm it由于某些我完全忽略的原因,只使用了内部人员版本。

每当我注意到我不再需要使用 Insiders Edition 时,我都会更新此答案。


[更新] The official Visual Code AUR page 显示了可用的不同版本:

以下包提供VSCode:

  • 代码(开源发布)
  • visual-studio-code-bin AUR(Microsoft 品牌版本)
  • code-git AUR(开发中的开源版本)

我想我一开始可能安装了错误的版本(非内部人员是开源版本:code

实际上,当使用网站上的官方tar.gz(这相当于安装visual-studio-code-bin)时,它运行良好。

正确的方法是(显然)使用 Microsoft 官方品牌版本:visual-studio-code-bin

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    • 2018-07-09
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    相关资源
    最近更新 更多