Reputation: 31
I'm using VS code to write a simple .NET console application. Here's a look at my app's entry point:
Program.cs
:
using System;
namespace MyApp
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine("test");
Console.WriteLine("another test");
}
}
}
I set a breakpoint on the line that reads, Console.WriteLine("test")
, and start VS Code's debugger. The debugger highlights the line I've selected once it reaches that point in execution. Great. Then I press the "step over" button.
Expected behavior: test
will be written to the debug console and the debugger will advance to the next line of code.
Actual behavior: test
is not written to the debug console. Execution stops immediately and the console reads: The program '[3803] MyApp.dll' has exited with code 0 (0x0).
I re-launch my simple application without changing anything. The debugger once again stops at Console.WriteLine("test")
. This time I press F5 to continue running. Again, nothing is written to the console and I am shown that the app has exited with code 0
.
I re-launch the app, again. When the debugger stops at Console.WriteLine("test")
, I un-set my breakpoint and press F5. test
is written to the console, followed by another test
, and the application finishes (with code 0
, of course). I've found that the debugger will break at a later breakpoint, but I must un-set each breakpoint as it is reached (and then continue running / press F5)... otherwise the application stops running and I'm shown the same, simple exited with code 0
message. Un-setting a breakpoint makes no difference for "stepping over" / "stepping into" - those commands do not seem to work at all.
For what it's worth, I'm working on a MacBook running macOS Big Sur on an Apple M1 chip (I have no idea if this is useful information). Here is more detailed information about my workspace configuration:
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"
}
]
}
How can I get VS Code's debugger to work as expected?
Upvotes: 1
Views: 1618
Reputation: 31
I believe that the .NET 5.0 SDK is not fully compatible with the new Apple M1 chip. I followed the process below on two Macs: one with an Intel chip and the other with an M1 chip:
dotnet new console
to create a new console application..vscode/launch.json
, open it, and click the "Add Configuration" button. Select .NET: Launch .NET Core Console App
. Update all placeholder-text in the file according to the structure of your project. You'll also need to create a .vscode/tasks.json
file like the one that I included in my original post.Running and debugging the application with this launch configuration works as expected on my Intel-chip-Mac, but not on my M1-chip-Mac. Looks like I'll be working from my old Mac until an M1-compatible .NET SDK is released.
Upvotes: 1