Visual Studio Code调试默认的ASP.NET Core MVC WebApp:不起作用 [英] Visual Studio Code debugging the default ASP.NET Core MVC WebApp: does not work

查看:105
本文介绍了Visual Studio Code调试默认的ASP.NET Core MVC WebApp:不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Manjaro linux and tried to debug the default ASP.NET Core MVC project but the debugging stopped without any error

我使用以下项目创建了该项目:<$ 文件夹中的c $ c> dotnet新mvc ,没什么特别的,然后添加了一个新配置 .NET Core启动(网络)

I created the project with: dotnet new mvc in a Meow folder, nothing special, and then added a new configuration .NET Core Launch (web).

事实证明,只有一个调用 dotnet构建 preLaunchTask tasks.json 中的 build 任务中定义的c> launch.json 的c $ c>就是这样,调试过程开始和停止而没有显示任何错误。

It turns out that there is only a call to dotnet build defined in the build task in tasks.json as defined in preLaunchTask of the launch.json and that's it the debugging process starts and stops without showing any error.

运行 dotnet运行时,一切正常,因此我怀疑问题更多来自于Visual Studio调试配置。

When running dotnet run, everything works, so I am suspecting the issue comes more from my Visual Studio debug configuration.

在终端标签中,我有:

In terminal tab I have:

> 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.

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

The two files below that have been auto generated look fine.

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):

Tried to uninstall omnisharp and reinstall it (with a VSCode reboot in between):

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]

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

The debugger is installed properly (I tried a brand new fresh installed):

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

也向Github提交了问题

推荐答案

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

I answered my own question on those GitHub issues:

  • https://github.com/OmniSharp/omnisharp-vscode/issues/2604#issuecomment-460593882
  • https://github.com/OmniSharp/omnisharp-vscode/issues/2837

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

Basically steps of my solution on a fresh Manjaro Gnome variant live session:


  • 安装~~ 在不使用命令行的情况下享受AUR: sudo pacman -Sy yay ~~ yay -S dotnet-sdk mono binutils msbuild-stable visual-studio-code-bin --noconfirm (请参见下面的[UPDATE])。

  • Install ~~yay to enjoy AUR without struggling with the command line: sudo pacman -Sy yay~~ yay -S dotnet-sdk mono binutils msbuild-stable visual-studio-code-bin --noconfirm (see the [UPDATE] below).

设置所需的一切(aka .NET Core SDK,Mono,MSBuild和Visual Studio Code Insiders): yay -S dotnet-sdk mono binutils msbuild-stable visual -studio-code-insiders --noconfirm

Setup everything you need (aka the .NET Core SDK, Mono, MSBuild and Visual Studio Code Insiders): yay -S dotnet-sdk mono binutils msbuild-stable visual-studio-code-insiders --noconfirm


  • 注意: binutils 导致Gnome变体似乎没有在本地嵌入该变量,这需要在 msbuild-stable 安装步骤之一中进行剥离。

  • Note: binutils cause the Gnome variant does not seem to embed that one natively, and this require for stripping in one of the steps of the msbuild-stable installation.

.bashrc末尾添加要导出的必需环境变量。 c $ c>文件放在您的主文件夹中:

Add the required environment variables that you would like to export at the end of your .bashrc file in your home folder:


  • export MSBuildSDKsPath = / opt / dotnet / sdk / $( dotnet --version)/ Sdks

  • export PATH = $ PATH:/home/manjaro/.dotnet/tools

  • export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
  • export PATH="$PATH:/home/manjaro/.dotnet/tools"

创建一个虚拟项目: dotnet new mvc

启动Visual Studio代码内部人员: code-insiders。

Start Visual Studio Code Insiders: code-insiders .

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

Install the C# extension CTRL + SHIFT + P ext install ms-vscode.csharp

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

Download the .NET Code Debugger for the C# extension (if needed / not already done the first time) CTRL + SHIFT + P Debug: Download .NET Core Debugger

生成 launch.json 任务.json 文件(如果尚未对弹出窗口回答是,则显示为:您是否要添加所需的资产来构建和调试项目?)
CTRL + SHIFT + P
.NET:生成用于构建和调试的资产

Generate the launch.json and tasks.json files (if not already answered yes to the popup shows: "Would you like to add the required assets to build and debug your project?") CTRL + SHIFT + P .NET: Generate Assets for Build and Debug

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

Install the tools for the development self-signed certificate dotnet tool install --global dotnet-dev-certs

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

Register the development self-signed certificate: dotnet dev-certs https

调试( .NET Core启动(网络)
CTRL + SHIFT + D
< kbd> F5

Debugging (.NET Core Launch (web)) CTRL + SHIFT + D F5

不过,这并不稳定,正如我在最初的评论中指出的那样帖子,Arch / Manjaro不受调试器的正式支持,但是我发现这与Visual Studio Code的版本更相关,由于某些我完全忽略的原因,atm仅与内部版本一起使用。

This is not stable though, as pointed by one of the comments in my initial post, Arch / Manjaro are not officially supported by the debugger, but I found that this is more related to the version of Visual Studio Code, atm it only worked with the insiders edition for some reasons I completely ignore.

每当我发现不再需要使用Insiders Edition时,我都会随时更新此答案。

I will keep this answer updated whenever I will notice that I will no longer need to resort to the Insiders Edition.

[更新]
官方的Visual Code AUR页面显示了可用的不同版本:

[UPDATE] The official Visual Code AUR page shows the different versions available:


以下软件包提供了VSCode:

The following packages provide VSCode:


  • 代码(开源发行版)

  • visual-studio-code-bin AUR(微软品牌发行版)

  • code-git AUR(开发中的开源版本)

我想我可能曾经有过首先安装了错误的版本(非内部人员是开源版本:代码

I think I may have had installed the wrong version at first (the non insiders one was the open source release: code.

实际上是通过网站上的官方 tar.gz 玩游戏(这是安装 visual-studio-code-bin )运行正常。

Actually when playing with the official tar.gz from the website (which is the hard way equivalent of installing visual-studio-code-bin) it worked fine.

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

The right way is to (obviously) go with the official Microsoft branded release: visual-studio-code-bin.

这篇关于Visual Studio Code调试默认的ASP.NET Core MVC WebApp:不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆