Debugging WP7 Deep Links on Live Tiles

Windows Phone 7.1 now includes the ability to pin Secondary Tiles to the user’s start screen. There are many tutorials out there on the net that describe how to implement them, but basically you provide the OS with the URI of the xaml page to load when the user taps on the tile.

The problem is how do you debug this?  When you F5 top start debugging in Visual Studio your app just runs normally.  How do you simulate the OS launching app via a specific page.

The easiest way is to simply add a BackgroundTask to your app.  You don’t actually have to create a BackgroundTask but simply add an entry for a dummy task to your WMAppManifest.xml.  It does not matter that the BackgroundTask you are pointing to does not exist.

 <DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/>
  <ExtendedTask Name="BackgroundTask">
      <BackgroundServiceAgent Specifier="ScheduledTaskAgent" 
        Name="ScheduledTaskAgent1" Source="DummyAgent"
        Type="DummyAgent.ScheduledAgent" />

The debugging behavior of Visual Studio changes once you have a BackgroundTask configured.  Visual Studio will now remain attached even after you quit your app.

This means you are able to debug your secondary tile deep links by launching your app as usual using F5, then quit out back to the phone start screen and re-launch it using your pinned secondary tile.  This will launch your app again using the deep link URI you provided when you created your secondary tile, but crucially since the debugger is still attached you will be able to hit any break points and debug as if you’d launched directly from Visual Studio using F5.

Don’t forget to remove the BackgroundTask entry from WMAppManifest before you ship your app, otherwise you will fail marketplace validation.