我正在使用 VS 代码编写一个简单的 .NET 控制台应用程序。这是我的应用程序的入口点:
Program.cs:
using System;
namespace MyApp
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("test");
Console.WriteLine("another test");
}
}
}
我在读取 , 的行上设置了一个断点Console.WriteLine("test"),并启动 VS Code 的调试器。一旦到达执行点,调试器就会突出显示我选择的行。伟大的。然后我按下“跳过”按钮。
预期行为:test将被写入调试控制台,调试器将前进到下一行代码。
实际行为:test未写入调试控制台。执行立即停止,控制台显示:The program '[3803] MyApp.dll' has exited with code 0 (0x0).
我重新启动了我的简单应用程序,没有进行任何更改。调试器再次停在Console.WriteLine("test"). 这次我按 F5 继续运行。同样,没有任何内容写入控制台,我看到应用程序has exited with code 0.
我再次重新启动应用程序。当调试器停止在 时Console.WriteLine("test"),我取消设置断点并按 F5。test被写入控制台,然后是another test,应用程序完成(with code 0当然是 )。我发现调试器将在以后的断点处中断,但我必须在到达每个断点时取消设置(然后继续运行/按 F5)......否则应用程序停止运行,我显示相同,简单的exited with code 0消息。取消设置断点对于“越过”/“进入”没有任何影响——这些命令似乎根本不起作用。
对于它的价值,我正在开发在 Apple M1 芯片上运行 macOS Big Sur 的 MacBook(我不知道这是否是有用的信息)。以下是有关我的工作区配置的更多详细信息:
MyApp.soln:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.808.8
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyApp", "MyApp\MyApp.csproj", "{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|anycpu = Debug|anycpu
Release|anycpu = Release|anycpu
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}.Debug|anycpu.ActiveCfg = Debug|anycpu
{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}.Debug|anycpu.Build.0 = Debug|anycpu
{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}.Release|anycpu.ActiveCfg = Release|anycpu
{D12824DE-83AF-4C7B-B5C2-C6CB1B9554C6}.Release|anycpu.Build.0 = Release|anycpu
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8A94F55D-F55A-450C-A412-10554B4B7799}
EndGlobalSection
EndGlobal
MyApp.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/MyApp/bin/Debug/net5.0/MyApp.dll",
"args": [],
"cwd": "${workspaceFolder}/MyApp/bin/Debug/net5.0",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyApp/MyApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/MyApp/MyApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/MyApp/MyApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
如何让 VS Code 的调试器按预期工作?