In this blogpost I am going to show you how you can debug packages that reside in a Package Management Feed in Visual Studio Team Services (VSTS).
Setting the stage
The package represents a custom build package that can serve any generic functionality used by other applications. The package has its own solution and is automatically pushed to the Package Management feed by a CI Build.
In another solution we have an command line application that consumes this package and we like to have the ability to be able to debug through that code without having to do any other plumbing. We want to treat the package as if we don’t know where the source is.
There are some pre-requisites to this, you need to have Package Management in VSTS. AND there is the need to have the private preview of the Symbol Server for VSTS. This can be requested here: https://docs.microsoft.com/en-us/vsts/package/symbol/setup. A public preview is to be expected, so be sure to keep an eye out for this!
Setting up the Package creation Build
Publishing the package to the VSTS feed is fairly straightforward. I use a PowerShell script verion my package assembly as well as applying that version to my packages. This way every package gets a new version and is easily traceable. Let’s check the steps that are involved in this build.
First I run my versioning PowerShell script. An environment variable is set in the script (real production usage work needs a bit of tweaking) and that environment variable is used during the NuGet Pack operation to version the package.
After that the symbols are published. This is a mandatory step to get the debugging running.
The symbols are published to a new Symbol Server Type: Team Services. This is a hidden area in VSTS that will store your PDB files.
The result of a successful build is that we see a new package deployed to the feed, with the desired versioning scheme, but more importantly we see that the Artifacts of this particular build are enhanced!
We see that besides the usual drop artifact there is another artifact available. This artifact is not downloadable nor explorable but this artifact contains the valuable PDB files that allow us to debug the package!
Consuming the package
Consuming our created package is like any other NuGet package but this one comes from your VSTS Package Management Feed. The location of the feed can be configured in Visual Studio.
In my Package Consumer I have just a reference to the package, as can be seen in my installed packages overview.
Debugging the package
Now lets hit F5 and debug to some lines of code;
The Mammal class is defined IN the package, that usually would be a blackbox to me but since this is my own package I can now easily step into the code without having to setup anything else!
This is really cool, easy and very convenient! Happy Debugging!
There are some quirks in the private preview. One involves authentication against your VSTS environment. This was resolved in the latest Visual Studio Update 15.4.2. The following post refers to the issue; https://developercommunity.visualstudio.com/content/problem/93310/source-code-does-not-load-via-source-server-for-sy.html
Getting the code
All the code is placed on GitHub in following repositories:
Package Solution: https://github.com/JasperGilhuis/Package
Package Consumer Solution: https://github.com/JasperGilhuis/Package-Consumer