I have been working on some Windows Media Center application debugging and deployment scenarios recently so that we can enhance some of the documentation in the Windows Media Center SDK for Windows Vista. I want to document one of the interesting configurations here in case it is useful in your Windows Media Center application development scenarios.
Before I get started, I want to note that the steps listed below work equally well if you are developing in Visual C# 2005 Express Edition or Visual Studio 2005 Standard or higher. For simplicity's sake, I will refer to both by the single name "Visual Studio" in the instructions below.
Step 1: Getting started
I started by installing Windows Vista RC1 (Ultimate Edition), Visual C# 2005 Express Edition and the Windows Media Center SDK for Windows Vista RC1. Then, I created a Visual C# Windows Media Center Presentation Layer (WMCPL) application in Visual C# Express.
By default, the WMCPL application is configured to launch the standalone version of McmlPad and navigate to the file default.mcml that is a part of the project. The steps below allow you to configure the WMCPL project so that it will register the application with Windows Media Center and automatically launch the Windows Media Center shell and navigate to the application when pressing F5 to build and debug in Visual Studio. The steps require you to make some modifications directly to the .csproj file, and then make some modifications to the project settings in the Visual Studio IDE.
Step 2: Modify settings in the .csproj file
Open the .csproj file for your WMCPL application project (located at c:\Users\<username>\Documents\Visual Studio 2005\Projects\<solution name>\<project name> by default) in a text editor such as notepad and make the following changes:
- Override the pre-build target so that Visual Studio will ignore pre-build event errors using the technique described in this blog post. You can do this by adding the following section to the bottom of the .csproj file just before the closing </Project> tag:
<Target Name="PreBuildEvent" Condition="'$(PreBuildEvent)'!=''" DependsOnTargets="$(PreBuildEventDependsOn)">
<Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" IgnoreExitCode="true" />
</Target>
- Change the <StartProgram> to be $(windir)\eHome\ehshell.exe (replacing the default value of $(windir)\eHome\McmlPad.exe)
- Change the <StartArguments> to be /entrypoint:{<app_guid>}\{<entrypoint_guid>} /addinfallbackpath:"$(FullyQualifiedOutputPath)" (where <app_guid> and <entrypoint_guid> are the GUIDs listed in the App.xml file that is generated when you create a new Windows Media Center Presentation Layer Application)
- Save the changes and close the .csproj file
Step 3: Update project settings in the Visual Studio IDE
After modifying and saving the WMCPL application .csproj file using the steps listed above, open it in Visual Studio and perform the following steps:
- Right-click on the project in Solution Explorer and choose Properties
- Click on the Build Events tab in the Property Pages
- Add the following text to the Pre-build event command line text box: %windir%\eHome\RegisterMceApp.exe /u App.xml
- Add the following text to the end of the Post-build event command line text box (make sure to leave the command line there that appears by default to run mcmlverifier.exe to validate the MCML syntax in your project): %windir%\eHome\RegisterMceApp.exe App.xml
- Click on the File menu and choose Save All to save the updated project settings
Once you have completed all of the above steps, you can press F5 in the Visual Studio IDE to build and run the WMCPL application, and it will launch Windows Media Center and navigate directly to the application by using the /entrypoint command line switch that is available for ehShell.exe.
I have found these steps useful when I want to rapidly preview a WMCPL application hosted within Windows Media Center because I do not need to manually register the application and add the application assembly to the global assembly cache (GAC) each time I rebuild it. Note that you will want to eventually add a strong-name key to your assembly, create an installer for your application (using a technique such as this) and install the assembly to the GAC for real-world deployment scenarios.
Unfortunately, you cannot use Visual Studio to debug the application code if you directly launch it in Windows Media Center using the above steps. Visual Studio attaches to the process that it launches (which in this case is the Windows Media Center shell application - ehShell.exe). Each application hosted in Windows Media Center is then launched in a new instance of the Windows Media Center hosting application - ehExtHost.exe. That ehExtHost process is the one that you need to attach to in order to debug the application code. You can, however, use steps like the ones documented in this previous blog post to attach and debug application code within ehExtHost.exe.
Hopefully you will find this technique useful in some of your Windows Media Center application development scenarios.
Aaron