Debugging your custom LightSwitch (Shell) Extension.

<< Stop right there! Using the ExtensionsMadeEasy extension, you can be debugging your extensions in just 5 steps without having to modify the extension’s properties… If you want to debug a shell extension, read this easy guide.  However, the original approach described below is still valid!>>

As a lot of people, I immediately fell in love with Lightswitch from the first time I saw it, which was in a presentation by Gill Cleeren at MS Tech Event 2011.  Ever since, I’ve been trying to spread the LightSwitch love to the people around me.

One of the sexy things about LightSwitch, besides the actual speed of creating LOB applications, is the ease of extensibility.  Usually, when given the chance give a presentation, I would show off the BingMapControl, ofcourse activating it the first time from the runtime “edit screen” designer, followed by a simple custom data source (WCF RIA service I mapped over a Twitter API call).

Next, a custom theme (“VB6 theme”: mix in random pastel colors and get a good laugh from the audience), to end my presentation by showing off the LightSwitch Beta2 Extensibility Cookbook custom shell extension.

Bad move of course, because that extension had about the sex appeal of launching a URL from a console application.  O wait, it has exactly the same sex appeal of launching a URL from a console application.  But hey, what was one to do, with no official documentation on the anatomy/API of a LightSwitch shell, and what was even worse, not one single guide, blog post or forum reply about how to debug the extension at all.

Thankfully, about 24 hours after launching LightSwitch, the team posted the official LightSwitch Toolkit,  including a link to a complete walk-through on how to create a custom shell.  Yes! Read the walk-through to the end, and see how easy it is to debug your extension:  have your vsix project launch a new instance of visual studio in experimental mode, which should take no more then 40 seconds on a standard computer. Then, in your second instance, open your LightSwitch test project, another 1.5 minutes of your time.  Activate the extension from the property page, only 15 seconds there, select it as the shell to use, and launch your test application.  Find out you made a rather small typo, hit the stop debugging button in anger, close the second instance of visual studio by repeatedly hitting the close button, smash your fists on the desk while windows is busy “looking for a solution” because visual studio crashed, turn of your computer, go for a walk to calm down, turn your computer back on, rinse and repeat.

Official note on testing the extension

Official note on testing the extension

Exaggerated, true. But seriously, this is how we are supposed to debug our extensions?  As RayWJ fans would say: “Balls to you”!

Here’s the alternative, slightly easier approach.

1. Follow the guide up untill the point where it tells you how to test the shell extension.

2. Open your vsix project’s debug folder, and execute your extension’s installer.

Install the extension

Install the extension

3. Restart visual studio. (Last time, promised).

4. Create a new LightSwitch project (I called mine ShellExtension.TestArea), or open an existing one.

5. On the property page of your LightSwitch project, activate your shell extension and select it as the shell to use in your LightSwitch application.

6. Here’s the first line of magic: right-click on your solution, and pick “add > add existing project” from the context menu. Add the project ShellExtension.Client that you created in the walk-through.  Because this is a shell, we really don’t care about the other projects.

After adding shell extension client project

After adding shell extension client project

7. Second and last line of magic, go to the tab “build events” from the properties of your ShellExtension.Client project, and enter this post-build evend command (all in ONE line):

if $(ConfigurationName) == Debug copy “PATH_TO_SHELL_EXTENSION_CLIENT\Bin\Debug\ShellExtension.Client.dll” “PATH_TO_SHELL_EXTENSION_TEST_AREA\_Pvt_Extensions\ShellExtension\Client\Reference\ShellExtension.Client.dll”

8. Add an extra whitespace in your shell page’s XAML or something (no changes = no new build = no post-build events would occur), set a breakpoint and hit F5.

9. Look mon, I’m debugging!

Look mon I'm debugging

Look mon I'm debugging

Have fun using LightSwitch, and don’t hesitate to tweet me with any questions, remarks or just to show off your cool looking custom extensions (@janvanderhaegen).

Advertisements

9 thoughts on “Debugging your custom LightSwitch (Shell) Extension.

  1. Excellent stuff. I’ve been really excited about the release of the Extension toolkit, more so than the RTM of Lightswitch. Just downloaded it before bed last night and today I start in earnest.

    A great post to wake up to.

    Thanks

  2. Thank you! I am starting to learn LS and the customization feels to be a pain in the ass. You suggestion helps a bit though.

  3. Pingback: Happy 4th anniversary! | Jan Van der Haegen's blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s