Last week I read this tweets from Maxime Rouiller (@MaximRouiller):

Then I found out that SourceLink is a language-and source-control agnostic system for providing first-class source debugging experiences for binaries."

What that means is that, once you enable SourceLink, the users are able to step into your code without effort! from both Visual Studio and Visual Studio Code which are ready to let you enjoy the experience.

This findings triggered my interest and started wondering on how could I add such a nice feature to the netDumbster project.

Here is what I did:

1. Added the following properties to the project’s csproj#


2. Added the following ItemGroup to the project’s csproj#

2  <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All"/>

Note: this Package Reference depends on the source control system.

3. Finally built the nuget package as usual#

1dotnet pack -c release

Believe me that was all!!! So then I tested the new package and features with a simple console application and Visual Studio Code:

1. Created a new console project#

1mkdir SourceLinkTest
2cd SourceLinkTest
3dotnet new console
4dotnet add package netDumbster -v
5dotnet restore

2. Replaced the contents of Program.cs with the following code#

 1using System;
 2using netDumbster.smtp;
 3using netDumbster.smtp.Logging;
 5namespace a
 7    class Program
 8    {
 9        static void Main(string[] args)
10        {
11            LogManager.GetLogger = type => new ConsoleLogger(type);
12            SimpleSmtpServer.Start();
13        }
14    }

3. Generated Assets for Build and Debug for .NET#

Inside Visual Studio Code and from the Command Palette invoke the .NET: Generate Assets for Build and Debug command so it creates the launch.json and tasks.json files inside the .vscode folder.

4. Replace the contents of launch.json with the following configuration#

 2   // Use IntelliSense to find out which attributes exist for C# debugging
 3   // Use hover for the description of the existing attributes
 4   // For further information visit
 5   "version": "0.2.0",
 6   "configurations": [
 7        {
 8            "name": ".NET Core Launch (console)",
 9            "type": "coreclr",
10            "request": "launch",
11            "preLaunchTask": "build",
12            // If you have changed target frameworks, make sure to update the program path.
13            "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/SourceLinkTest.dll",
14            "args": [],
15            "cwd": "${workspaceFolder}",
16            // For more information about the 'console' field, see
17            "console": "internalConsole",
18            "stopAtEntry": false,
19            "internalConsoleOptions": "openOnSessionStart",
20            "justMyCode": false,
21            "suppressJITOptimizations": true
22        },
23        {
24            "name": ".NET Core Attach",
25            "type": "coreclr",
26            "request": "attach",
27            "processId": "${command:pickProcess}"
28        }
29    ,]

Note: the configuration disables justMyCode and enables suppressJITOptimizations.

I added a breakpoint in line 12 of Program.cs and started debugging. Once the debugger hit the breakpoint I pressed F11 to “Step Into” the netDumbster code. And surprise! I was in!!!

image shows the debugger inside netDumbster&rsquo;s code

Now let me ask you something: What are you waiting to get out there and add SourceLink to your existing library?

Hope you enjoyed the ride!