Source Link with an Azure DevOps Symbol Server

狂风中的少年 提交于 2019-12-03 13:20:55

Well, I should have read and followed this answer before posting my question because this was the missing piece of the puzzle.

I needed to follow steps 5 and 6 of Eric's blog post but I actually didn't need to modify my pack command because I'm not including the .pdb file in the Nuget Package.

[EDIT 2]:

Note: So far I could only get this working if the Nuget Package is generated with the Debug Build Configuration. If you find a way to get Source Link working with a Release DLL inside the Nuget Package, please answer my other question. Thank you

[EDIT]: Since I wrote a documentation for my company, here it is:

Summary:

This requires two things:

  • Having access to the Symbol file of the project (.pdb) which is a mapping file used by the debugger
  • Enable Source Link support so Visual Studio knows where it should look to download the source code while debugging

Set Up:

Component's project

For each project in your solution:

  1. Only if you plan consumers of the Nuget package to use Visual Studio 2017. This step isn't required with you want to use Source Link with Visual Studio 2019:

    In Visual Studio, right click on your project -> Properties then go to Build -> Advanced and change the Debugging Information from Portable (default value) to Full

  2. Install the Microsoft.SourceLink.Vsts.Git Nuget Package (You must check the Include prerelease checkbox in Visual Studio)

  3. Edit the .csproj file and include the following code in the first PropertyGroup element:

 <PublishRepositoryUrl>true</PublishRepositoryUrl>
 <EmbedUntrackedSources>true</EmbedUntrackedSources>

Azure DevOps build pipeline

  1. Create a pipeline variable called BuildConfiguration (if it doesn't exist already) and set the value to Debug

    • Use this variable as argument in your .NET Core Build task: --configuration $(BuildConfiguration)
    • In your .NET Core Pack task, use this variable in the Configuration to Package field: $(BuildConfiguration)
  2. At the end of your pipeline you must have a task Index Sources & Publish Symbols

    • In the Artifact name field, the BuildConfiguration variable must be used too: Symbols_$(BuildConfiguration)
  3. Of course you must also have a .NET Core Push task to push you Nuget package to your Azure DevOps Nuget Feed

Visual Studio

  1. Tools -> Options -> Debugging -> Symbols click on the New Azure DevOps Symbol Server Location... button and authenticate to the server
    • Set the cache folder to a convenient location like C:\Symbols\. This is where all your .pdb files will be stored

  1. Tools -> Options -> Debugging -> Symbols click on Load only specified modules. You can here specify the Symbol files of DLLs you want to load.

    If you don't do this and leave the default to Load all modules, unless excluded, Visual Studio will take a very long time to load everything when you run your program in debug mode.

    Tips : To see all the DLLs loaded by your project, when you're debugging, click on Debug -> Windows -> Modules. From here you can view the full list, select multiple and then right click Copy Value -> Copy Name

  1. Tools -> Options -> Debugging -> General
    • Uncheck Enable Just My Code
    • Check Enable source server support
    • Check Enable Source Link Support

Consuming project

When you want to debug inside the Nuget Package's code, naturally press F11 to step into it and Visual Studio will ask if you agree to download the source code from your Azure DevOps repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!