- Pivotal Cloud Foundry (PCF)
- Applications using .NET core buildpack
There is now a way to debug .NET Core application from Visual Studio on PCF with Linux cells. The solution involves hooking into MI Debug engine to pipe debugging data over SSH. While Visual Studio does have support for debugging over SSH, it expects you to provide ip, port, and credentials. Hooking into “cf ssh” is a trickier - here’s how you do it.
First, we need to bundle CLRDBG with your application. The official release of clrdbg requires the presence of libunwind on the cell, which is not included currently. However, we can still make it work by bundling the required dependencies from libunwind into clrdbg. There is now a custom clrdbg package which includes the necessary libunwind dependencies, which is published here: https://github.com/macsux/cfdotnetdebug/releases/download/1.0/clrdbg-ubuntu.14.04-x64-libunwind8.zip. From here, we need to bundle it with the artifacts we’re publishing (in future this should be done via buildpack). From there we going to ssh into our container and record the PID of the app we’re going to attach debugger to. This is fed into an “instructions” xml file for the debugger, which includes the command to use
cf ssh and the process ID we want to attach to. Finally we use a special command in visual studio in order to use this xml file to spawn our debug session.
Step by step:
- Download CLRDBG with libunwind
- Publish your app with debug symbols
dotnet publish -f netcoreapp2.0 -r ubuntu.14.04-x64 -c Debug -o publish
- Extract the downloaded zip into your
cf pushthe app from the publish folder
launch.xmlfile as following:
<PipeLaunchOptions xmlns="http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014" PipePath="cf.exe" PipeArguments="ssh YOUR_APP_NAME -command "~/app/clrdbg/clrdbg --interpreter=mi"" TargetArchitecture="x64" MIMode="clrdbg" ProcessId="41"> <LaunchCompleteCommand>None</LaunchCompleteCommand> </PipeLaunchOptions>
Make sure to adjust PipeArguments
- Run the following command and record PID of your app
> cf ssh YOUR_APP_NAME --command "ps -d"
- Replace the value of ProcessId in launch.xml with PID for your app
- From Visual Studio, open Command window (View > Other Windows > Command Window)
- Run the following in VS Command Window
Debug.MIDebugLaunch /Executable:dotnet /OptionsFile:"C:\FULL_PATH\launch.xml"
We should now be debugging.
Dotnet-core on github: https://github.com/cloudfoundry/dotnet-core-buildpack