Stephen's profileBadCorporateLogoPhotosBlogLists Tools Help
    January 22

    Debugging Custom Content Pipeline Extensions (Part 2)

    In my previous post, I described what happens when you press F5 to debug a game project, and explained why you can't debug your Content Pipeline Extension Library projects that way. However, I also described many ways in which F5 actions can be customized. By tweaking the settings in just the right ways, it turns out that you can debug your Content Pipeline Extension Library projects in the IDE. Here's how you do it...

    XNA Game Studio (XGS) 2.0 projects use a nested Content project to build content. If you look at your project directory in Explorer, you'll find a file called content.contentproj. That's the MSBuild project that builds all your content.

    If you want to debug custom components that you use to extend the Content Pipeline, it's as easy as debugging msbuild.exe while it builds the content.contentproj project file. In Visual Studio 2005 (VS), you can accomplish this by changing your Startup Project to launch an external program (msbuild.exe) and pass it the path to your content.contentproj file as a command-line argument (this is described in the XGS documentation, near the bottom of this page on How To: Write a Custom Importer and Processor). The problem, however, is that it's still difficult to set up, and the options described aren't available in Visual C# 2005 Express Edition (VCSExpress).

    It turns out that although there is no user interface to change the startup program in VCSExpress, the ability to launch and debug another application is still there. If you want to have a C# Startup Project launch msbuild.exe when you start debugging, all you need to do is add the following XML to its .csproj file (after the <Import> element near the bottom is a good spot).

    <PropertyGroup>
      <StartAction>Program</StartAction>
      <StartProgram>$(MSBuildBinPath)\msbuild.exe</StartProgram>
      <StartWorkingDirectory>$(ProjectDir)</StartWorkingDirectory>
    </PropertyGroup>

    If you want to debug your Content Pipeline components, then you need to add another property, StartArguments, to specify the .contentproj to build, the platform to build it for (Xbox 360 or Windows), and the configuration to build (Debug or Release).

    It can get a bit long, but to do it right, you need something like this...

    <StartArguments>"Content\Content.contentproj" /p:Configuration="$(Configuration)" /p:Platform="$(Platform)" /p:XnaPlatform="$(XnaPlatform)" /p:ParentProjectDir="$(ProjectDir)"</StartArguments>

    If you add these properties to your game project (or game library project), it will launch and debug msbuild.exe as it builds the project's content using the Content Pipeline. That will let you hit breakpoints in your Content Pipeline Extension Library project after hitting F5.

    The caveat to all this is that it's tedious. It's also a bit dangerous to edit the XML project files directly, because if you don't know exactly what you're doing, you can end up with a project that won't load, and no idea how to fix it!

    One way to make this super convenient and risk-free would be to have a project template to create projects already configured to debug the Content Pipeline! Well, stay tuned! That will be my next post...

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    Stephen Styrchak has turned off comments on this page.

    Trackbacks

    The trackback URL for this entry is:
    http://badcorporatelogo.spaces.live.com/blog/cns!43EB71B104A2D711!166.trak
    Weblogs that reference this entry
    • None