Search code examples
sourcelink

SourceLink in VSTS


I'm trying to integrate SourceLink into Visual Studio Team Services by using https://github.com/ctaggart/SourceLink I have problems with it since the package seems unable to parse the URL of a VSTS repository.

Build started 8/22/2017 11:58:18 AM.
 1>Project "D:\Repos\Core\classic-stats\src\Acme.Stats\Acme.Stats.csproj" on node 1 (Build target(s)).
 1>SourceLinkCreate:
     git rev-parse --show-toplevel
     D:/Repos/Core/classic-stats
     git config --get remote.origin.url
     https://acme.visualstudio.com/DefaultCollection/Core/_git/classic-stats
     git rev-parse HEAD
     8c6a68b325cf10b67332aa2ea15db952a88d027d
     SourceLinkUrl:
     unable to convert OriginUrl: https://acme.visualstudio.com/DefaultCollection/Core/_git/classic-stats
 1>Done Building Project "D:\Repos\Core\classic-stats\src\Acme.Stats\Acme.Stats.csproj" (Build target(s)) -- FAILED.

Build FAILED.
0 Warning(s)
0 Error(s)

AFAIK there's only support for GitHub and BitBucket, am I right? Has anybody been able to integrate this into TFS builds? Thanks


Solution

  • As Skorunka stated in his comment, SourceLink now has support for VSTS (recently renamed Azure DevOps)

    Install the Microsoft.SourceLink.Vsts.Git Microsoft.SourceLink.AzureRepos.Git package in your project and add the following to your .csproj file

    <PropertyGroup>
        [...]
        <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
        <PublishRepositoryUrl>true</PublishRepositoryUrl>
        <EmbedUntrackedSources>true</EmbedUntrackedSources>
    </PropertyGroup>
    

    Configure your Build Pipeline to generate your Nuget package using the dotnet pack command. SourceLink doesn't work yet with the Nuget pack (based on my tests).

    Push your changes to your Azure DevOps server and let the build pipeline generate your Nuget package and push it to your Nuget feed.

    In Visual Studio go to tools -> Option -> Debugging -> General and ensure that

    • Enable just my code is not checked
    • Enable SourceLink support is checked

    Then in any other project, install your Nuget package.

    When you'll try to step into some code defined in your package's DLL, Visual Studio will ask if you want to Download source code and continue debugging. It will authenticate to your Azure DevOps server using your Git credentials, download the source code, and let you debug it.