Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go to Implementation with sourcelink

How can I enable visual studio to 'Go to implementation' for library code that is exposed with SourceLink?

We recently began using SourceLink in our .NETcore library in an attempt to debug the library while consuming it. We enabled SourceLink using this project: ctaggart/SourceLink by adding the following line to our csproj:

<PackageReference Include="SourceLink.Embed.AllSourceFiles" Version="2.6.0" PrivateAssets="All" />

This has worked great in that I are now able to step into the library code with the debugger, but I am unable to jump to implementation/definition of any of this library code. Is there a way I can get visual studio to do this?

like image 823
Nick BL Avatar asked Dec 20 '17 00:12

Nick BL


2 Answers

Being able to navigate to the source of a NuGet package is something that is being considered but has yet to be done. You can track its progress at https://github.com/dotnet/roslyn/issues/24349.

like image 127
TylerBrinkley Avatar answered Nov 14 '22 16:11

TylerBrinkley


SourceLink is now a .NET Foundation project at https://github.com/dotnet/sourcelink/.

First, configure how Source Link will behave:

You can enable SourceLink experience in your own project by setting a few properties and adding a PackageReference to a SourceLink package:

<Project Sdk="Microsoft.NET.Sdk">
 <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>

    <!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
    <PublishRepositoryUrl>true</PublishRepositoryUrl>

    <!-- Optional: Embed source files that are not tracked by the source control manager in the PDB -->
    <EmbedUntrackedSources>true</EmbedUntrackedSources>

    <!-- Optional: Include the PDB in the built .nupkg -->
    <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
  </PropertyGroup>
  <ItemGroup>
    <!-- Add PackageReference specific for your source control provider (see below) --> 
  </ItemGroup>
</Project>

Then, add the Source Link package that matches your repository. Packages are currently in pre-release and these are the available ones:

github.com and GitHub Enterprise

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

Visual Studio Team Services

<ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.Vsts.Git" Version="1.0.0-beta-63127-02" PrivateAssets="All"/>
</ItemGroup>

Team Foundation Server

<ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.Tfs.Git" Version="1.0.0-beta-63127-02" PrivateAssets="All"/>
    <SourceLinkTfsGitHost Include="tfs-server-name" VirtualDirectory="tfs"/>
</ItemGroup>

GitLab

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

Bitbucket.org

<ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.Bitbucket.Git" Version="1.0.0-beta-63127-02" PrivateAssets="All"/>
</ItemGroup>
like image 32
Marco Thomazini Avatar answered Nov 14 '22 14:11

Marco Thomazini