December 29, 2006

Visual Studio Build Events for MCML Applications

Filed under: Uncategorized — Anthony Park @ 2:41 pm

While working on MCEMailbox, I wanted a way to easily register my Media Center Markup Language (MCML) application with Media Center whenever I made a change. The default project template already includes a post-build step to run the MCMLVerifier. So, I modified the pre and post-build step to include the following extra tasks:

  • Unregisters the previous add-in with Media Center
  • Registers the new assembly in the Global Assembly Cache (GAC)
  • Registers the new add-in with Media Center

    To apply these post-build steps to your project:

    1. Right-click on the project in the Solution Explorer and select Properties
    2. Switch to the “Build Events” tab in the Properties window
    3. Set the Pre-build event command line to the following:

    %windir%\eHome\RegisterMCEApp.exe /u $(ProjectDir)App.xml
    if errorlevel != 0 exit 0

    4. Add the following text to the end of the Post-build event command line text box (make sure to leave the line that runs MCMLVerifier.exe):

    if errorlevel != 0 exit errorlevel
    "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /nologo /i "$(TargetPath)" /f
    if errorlevel != 0 exit errorlevel
    %windir%\eHome\RegisterMCEApp.exe $(ProjectDir)App.xml

    5. Build your project and smile. Hopefully, this will make debugging/retesting things a little bit easier.

    Note: This will only work if you are running Visual Studio 2005 as an Administrator. The step which runs gacutil to install the library in the GAC will fail if you are not an Administrator.

    1. Important note: If you copy-paste the build steps from this page, make sure to change the quotation marks back to regular double quotes (rather than spiffy opening/closing quotation marks). So instead of this:

      “C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe” /nologo /i “$(TargetPath)” /f

      you want this:

      "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /nologo /i "$(TargetPath)" /f

      At least you have to do this to run it from a command line, maybe Visual Studio is smart enough to translate these internally. VS doesn’t give an error, but then again it doesn’t give an error when the assembly isn’t strong named either–both give errors from the command line.

      Comment by Walker Hagius — April 26, 2007 @ 9:13 pm

    2. D’oh! The software running this site changes double quotes to fancy quotes automagically, so don’t copy/paste my example either. :) Just make sure to put regular quotes in manually.

      Comment by Walker Hagius — April 26, 2007 @ 9:15 pm

    3. Thanks for pointing this out, Walker. I have corrected the quotes that are displayed in this blog post so that they are normal quotes instead of the fancy ones.

      Comment by Anthony Park — April 27, 2007 @ 2:02 am

    RSS feed for comments on this post.

    Sorry, the comment form is closed at this time.