Skip to content

Instantly share code, notes, and snippets.

@kuri65536
Last active February 23, 2025 08:20
Show Gist options
  • Select an option

  • Save kuri65536/2338592d2ed34fc3fb3117a4b9c1b15e to your computer and use it in GitHub Desktop.

Select an option

Save kuri65536/2338592d2ed34fc3fb3117a4b9c1b15e to your computer and use it in GitHub Desktop.
Debug C# UnitTest codes with .Net Framework and VSCode in 2025

I spent long time to test my unit-test codes in VSCode. Here is the represantation steps to work the debug functionality.

create the projects

create the empty folder and open it from VSCode, then move to terminal view.

image

enter these commands to create the projects.

> mkdir codes
> mkdir tests
> cd codes
> dotnet new console --target-framework-override net472
> cd ..\tests
> dotnet new nunit --target-framework-override net472
> dotnet add reference ..\codes\codes.csproj
> cd ..
> dotnet new sln
> dotnet sln add ..\codes\codes.csproj
> dotnet sln add ..\tests\tests.csproj

change to build with net472

some language features in template are not allowed in .NET Framework 4.7.2. fix the codes

codes/codes.csproj

comment out two options::

    <!-- ImplicitUsings>enable</ImplicitUsings -->
    <!-- Nullable>enable</Nullable -->

codes/Program.cs

change codes to older style::

using System;
namespace codes {
    public class Program {
        public static void Main(string[] args) {
            Console.WriteLine("Hello, World!");
        }
    }
}

tests/tests.csproj

disable the option::

    <!-- Nullable>enable</Nullable -->

setup json to run as CLR

discribed in C# dev kit , launch.json is needed to change.

to create the launch.json, click the link in the debug panel.

image

you can input with suggestion, then change coreclr to clr

image

here is my launch.json

{
    "version": "0.2.0",
    "configurations": [{
        "name": ".NET Core Attach",
        "type": "clr",
        "request": "attach"
    }]
}

launch the debug

after you rebuild the project or reload the window, click the debug buttons in the Test panel.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment