Debug NuGet package with Azure Devops and Source Link
Asked Answered
D

2

10

I am trying to get SourceLink to work with a private NuGet package. I am running a netcore2.1 web application which references a netstandard2.0 NuGet package hosted on our Azure Devops NuGet feed.

Question 1: Does Source Link support .NET Standard packages?

I have followed the instructions in the guide here https://learn.microsoft.com/en-us/azure/devops/artifacts/symbols/setting-up-github-sourcelinking?view=vsts, which is basically:

  1. Add the Index Sources and Publish symbols package to my Azure Devops build.

  2. In Visual Studio, add our VSTS server as a symbols server

  3. In Visual Studio, enable Source Link support. I also tried enabling Source server support.

The Build pipeline Publish symbols path appears to be working - in the logs I see: Succeeded processing D:\a\1\s\src\MyCompany.Core.Services.SnapshotClient\bin\release\netstandard2.0\MyCompany.Core.Services.SnapshotClient.pdb:

When I start debugging my application I see a bunch of output in the VS Output window: 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\2.1.4\Microsoft.AspNetCore.Hosting.dll'. Cannot find or open the PDB file.

For my NuGet package I see "Symbols loaded" which seems promising.

FWIW I do not see the prompt from Visual Studio that "Source Link will download from the internet".

When I debug and attempt to Step-In to my NuGet package, it just steps over it.

I then tried:

  1. Headed over to https://github.com/dotnet/sourcelink and followed their instructions and installed the Microsoft.SourceLink.Vsts.Git package (Question 2 is that necessary?)

  2. When that didn't work, I upgraded every darn package in my application, which forced me to install .NET Core SDK 2.1.403

  3. Tried adding some stuff to the .csproj of my NuGet package, after trawling GitHub issues <PublishRepositoryUrl>true</PublishRepositoryUrl> <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> and <DebugType>portable</DebugType> <ci>true</ci> Now my .nupkg includes .pdb files too, which weren't there before. Still doesn't help me step in debug though.

  4. installed the sourcelink cli tools from https://www.nuget.org/packages/sourcelink/ and ran sourcelink print-urls on the .pdb from my .nupkg. Looks correct, I think? URLs are present.

  5. Disabled indexing after seeing a comment https://github.com/MicrosoftDocs/vsts-docs/issues/1336#issuecomment-414415049 from @mitchdenny . Still doesn't work.

And now I'm stumped as to why it's not working.

Diffraction answered 19/10, 2018 at 9:10 Comment(0)
R
15

I wrote a complete blog on how to do this using .NET Core & AzureDevops, but the steps should work for .NET Standard projects as well.

That said, some key takeaways that are missing from Microsofts documentation that you should know are:

  • The project's debugging information needs to change from "Portable" to "Full"
  • The AzureDevOps Nuget(restore, build, pack & push) need to use the .NET Core task.
  • The .NET Core build task should have an argument "--configuration" that passes in the value "debug". Doing so generates the .PDB file
  • The .NET Core pack task should use the "custom" command, with the custom command being "pack" and have the following arguments: "--include-symbols -v d" and a "-c" that passes in the value "debug". Doing so tells the pack command to include the .PDB file in the package.
Runner answered 10/1, 2019 at 17:45 Comment(3)
Thank Eric. I spent at least a day trying to figure it out at the time, and tried a few of those options. I've since moved on from that gig, but if I ever try it again I'll refer to your blog.Diffraction
Wow I should have read this answer before posting my question on SO. This should now be the accepted answer since including the .pdb file in the Nuget Package isn't no longer recommendedQuart
@Eric the certificate for your Website is invalid. You might want to check that.Attest
H
4

Question 1: Does Source Link support .NET Standard packages?

Yes. I successfully built a .NET Standard 2.0 library on Azure DevOps Pipeline, after which it was pushed to our private Azure DevOps Artifacts NuGet feed. Then, in a local project, I was able to step into the library (Visual Studio prompted me with a pop-up about downloading remote source code).

Here are the changes I had to make in the library's .csproj file:

<PropertyGroup>
  <PublishRepositoryUrl>true</PublishRepositoryUrl>
  <EmbedUntrackedSources>true</EmbedUntrackedSources>
  <AllowedOutputExtensionsInPackageBuildOutputFolder>
    $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
  </AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
...
<ItemGroup>
  <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All"/>
</ItemGroup>

Question 2: is that [PackageReference to Microsoft.SourceLink.GitHub] necessary?

I'm not sure. The docs suggest it is. But I removed the reference, re-built on Azure DevOps, and was still able to step through the library. Perhaps it's necessary for different environments (I'm keeping it just in case).

FWIW:

  • I'm debugging using Visual Studio 15.8.9
  • My latest installed .NET Core SDK is 2.1.403
  • My library's consumer is a .NET Core 2.1 executable
  • I compiled my library using Cake, which I have call into dotnet msbuild
Hornbeck answered 15/11, 2018 at 19:39 Comment(11)
I tried it and I get the link in the package metadata, but it's still not working. I see that my package doesn't contain any pub file but just a single dll. Can you tell us what's the content of your package? I'm also using the Nuget Package task from cake. Any special settings? Can you provide some more information about the building?Landlordism
I found that the pdb file was not included because I misspelled the AllowedOutputExtensionsInPackageBuildOutputFolder tag. With that one, the pub file is included. Anyway, I still cannot step into the package. Can you please provide some details about the Debugging settings in the Visual Studio options?Landlordism
Hmm that sounds frustrating! In VS, when I go to Debug -> Options -> General, I have Enable Just My Code and also Enable Source Link support checked (those seem like they might be relevant).Hornbeck
@Landlordism when you say you cannot step into the package, what exactly happens? Do you see a pop-up asking if you want to download source from a remote repo?Hornbeck
I have the same settings in VS. I never get the download prompt, but in the Debu window I can see the error message that the pdb file cannot be foundLandlordism
Did you do anything special for authentication against the private NuGet feed from Azure DevOps?Landlordism
No, I set up access to my feed with a simple command line: nuget sources add -name MyFeed -source http://pkgs.dev.azure.com/myfeed/index.json -username anyusername -password mypersonalaccesstoken123Hornbeck
Also, there's nothing special about my Cake script's DotNetCoreMSBuildSettings and NuGetPushSettings. I will mention that I'm using Cake but on the Azure DevOps vs2017-win2016 build image.Hornbeck
I finally found the problem: the application is targeting the full .net framework, but there is currently a bug in the SDK and this mixed scenario doesn't work. If I reference the packages from a test net core application everything works as expected. So much time wasted here!Landlordism
That sounds really frustrating, but glad you finally found the root issue!Hornbeck
Why are you using the Github package if you guys are in AzureDevops? A bit confused by this.Mada

© 2022 - 2024 — McMap. All rights reserved.