# Debugging with SourceLink

Microsoft and Visual Studio have introduced a new debugging technology called 'SourceLink' that enables source code debugging of certain .NET assemblies from NuGet. This feature has been enabled to allow developers to step into the native Umbraco CMS source code.

## Enabling SourceLink in Visual Studio 2017 & 2019

1. Navigate to **Tools** -> **Options** -> **Debugging** -> **General**.
2. In the **General** window, uncheck `Enable Just My Code` option and check `Enable Source Link support` option.
3. Click **OK** to save the changes.

   ![Visual Studio 2019 Debug Settings for SourceLink](https://3872888104-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgEH4FChbCn7eDDqREvdE%2Fuploads%2Fgit-blob-9fb55917f99acbe25d8b6ba356e7a71577a865c9%2FVS19-enable-sourcelink.png?alt=media\&token=fd62b6a1-ce6d-449c-87c7-7f7cc851dcf9)

## What is SourceLink?

To read about SourceLink, you can take a look at the following websites:

* [Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink)
* [Scott Hanselman blog post on Sourcelink](https://www.hanselman.com/blog/ExploringNETCoresSourceLinkSteppingIntoTheSourceCodeOfNuGetPackagesYouDontOwn.aspx)
* [SourceLink on GitHub](https://github.com/dotnet/sourcelink)

## Working with SourceLink

* Create a new `.NET 5.0` Framework blank/empty website.
* Install the latest Umbraco CMS 9.0+ Nuget Packages from Nuget.org
* Create an IComposer or similar code in your new site/SLN that you want to F11/Step Into. [Example Code Snippet to try with SourceLink](#example-code-snippet-to-try-with-sourcelink)
* Prompt will appear and the original source code file is fetched directly from GitHub. ![Visual Studio 2019 SourceLink dialog](https://3872888104-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgEH4FChbCn7eDDqREvdE%2Fuploads%2Fgit-blob-724dfacb8fe93849d6f7edb342691531044d20bf%2FVS19-sourcelink-prompt.png?alt=media)
* How far can you `F11`, also known as `Step Into`, and go down the rabbit hole of the Umbraco CMS source code?

### Example Code Snippet to try with SourceLink

```csharp
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;

namespace WebApplication23;

public class MyComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Components().Append<MyComponent>();
    }
}

public class MyComponent : IComponent
{
    private IContentService _contentService;

    public MyComponent(IContentService contentService)
    {
        _contentService = contentService;
    }

    public void Initialize()
    {
        // Add break point & F11 into me
        var root = _contentService.GetRootContent();

        foreach (var item in root)
        {
            // Add break point & F11 into me
            var udi = item.GetUdi();
            var foo = 5;
        }
    }

    public void Terminate()
    {
    }
}
```
