如何使用Visual Studio代码正确调试ASP.NET MVC核心



使用Visual Studio代码调试MVC ASP.NET Core应用程序时遇到困难。

我正在打开包含我要在VS代码中运行的项目的文件夹。

.csproj文件的相关部分如下:

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>aspnet-XXXXXXX-941AF9EA-C0DF-419D-B0F8-69FE3A477A65</UserSecretsId>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>$(SolutionDir)BuildsDebug</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
</Project>

现在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": "watch",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Builds/Debug/XXXXXXX.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\bNow listening on:\s+(https?://\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}

现在,当我打开一个代码文件,设置一个断点并选择启动应用程序时,会进行编译,但浏览器最终不会运行。。。

更令人惊讶的是,构建的输出到了终端,而不是调试控制台:

Executing task: dotnet watch run /Users/omatrot/Documents/bealink/bealink_server/XXXXXXX/XXXXXXX/XXXXXXX.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <

然后我按下CTRL+C来停止托管过程
VS Code然后立即再次运行它,这一次在调试控制台中输出,打开浏览器,并在我的断点上停止。

这在我看来很疯狂。

第1版:这是在Visual Studio下通过删除以下引用实现的:

<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.113" />

您需要先阅读官方文档,并知道我们需要在vscode中添加一些扩展。

你可以阅读Jason Watmore的博客,在博客中,详细介绍了如何调试。您可以创建task.json和launch.json。还有视频教程供我们参考。

相关内容

  • 没有找到相关文章

最新更新