XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Debugging Content Pipeline in 2.0

Last post 04-27-2008 12:51 PM by DJTN. 7 replies.
  • 11-23-2007 8:08 PM

    Debugging Content Pipeline in 2.0

        I was reading the documentation and found a section on setting up a project to allow debugging of a custom content pipeline. The though is! Will you only be able to do this in a visual studio 2005 retail sku, the particular Project Property does not seem to be in Express. If so and there won't be a way to do this in C# Express, is there any other parts of the framework which are only useful in a retail sku of VS?

    Cheers

    Kyle
  • 11-23-2007 10:08 PM In reply to

    Re: Debugging Content Pipeline in 2.0

    C# Express does not provide the functionality to attach the debugger to an existing process, or to specify what process the debugger should launch. So that technique for debugging custom processors will only work with the full version of Visual Studio.

    If you are limited to only free tools, I recommend the System.Diagnostics.Debugger.Launch method, using the CLR Debugger from the .NET SDK (the same as how you would debug processors with GSE 1.0).
    XNA Framework Developer - blog - homepage
  • 11-24-2007 6:40 PM In reply to

    Re: Debugging Content Pipeline in 2.0

    I've been playing around with the Beta 2.0 GS with Visual Studio 2005 Pro for a few hours, but I have hit a wall when it came to debugging content processors. I have what I guess is the typical Game solution:

    - My Game Project
    -    "Content" Sub-project
    - Custom ContentPipeline project
    -    Just contains a Model Processor and a Material Processor that are bypasses to the base classes, no custom processing yet.

    I set the dependency & reference to my Custom ContentPipeline DLL in the "Content" subproject, and assigned my custom model processor to a .FXB file. So far so good, the content gets build, and I know that my Model processor runs, because if I add a 'throw' in it I see that the content build aborts with my message.

    Now, debugging... how!?! I read the "Game Content Project" in the help, so I added a new windows game project to my Solution, called CustomContentPipelineTest. It was created with its own "Content" sub-project. I added my FXB file from the Game's Content subproject to the PipelineTest's Content subproject, added a reference & dependency to the custom ContentPipeline DLL, set the FXB to process using my custom model processor, then added the MSBuild command line to the "external program" in the Debug page.

    Everything seems to run fine, exactly as it should, and again if I set a 'throw' in my custom processor's code, I see that it gets thrown alright.

    BUT I can't manage to set breakpoints and singlestep into my Custom processor's code. I'm out of ideas.

    Another problem that is nagging me is that (might be related?), in order to Debug my test project, it needs to build the content first. However, if my custom processor has bugs, the build will fail and I won't be able to actually launch / debug the project (the MSBuild process launched in the command line)
  • 11-24-2007 9:04 PM In reply to

    Re: Debugging Content Pipeline in 2.0

    Ok, I think it works now. I restarted from scratch and this is what I did:

    My normal solution contains the projects as described above:
    - "MyGame" Project
    -    "Content" Sub-project
    - "CustomContentPipeline" project

    I added a new project to the solution. It was not a game project, but an Empty C# project. I called it "ContentPipelineTest".

    1 - I added the "CustomContentPipeline" project as a dependency of my new ContentPipelineTest project.

    2 - I opened the properties of the new ContentPipelineTest project. In Application | Output Type I set "Class Library". By default it tries to build an application, but since the project is empty and there are no source files, it will complain about a missing entry point.

    3 - I then went to the Debug tab, and set "Start External Program" to C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe.

    5 - In Command Line Arguments I added "Content.contentproj".

    6 - In the Working Directory I put the full path to my Solution. Note that "Content.contentproj" is inside my solution folder, side by side with the .sln file (it was converted from XNA 1.0). Unfortunately, the default path is somewhere inside the bin\x86\Debug folder, and you can't use the $(SolutionDir) macros in these fields, so the clunkiness of having a full path is needed. If need be, this can later be turned to a relative path with lots of "..\.." but for now it serves the purpose.

    8 - In "Build Events" added a Pre-Build step with the following command line: "if exist $(SolutionDir)bin\x86\Debug\Content\Models\MainShip.xnb del $(SolutionDir)\bin\x86\Debug\Content\Models\MainShip.xnb". The file MainShip.fbx is one of the content files that I have configured to run using my custom processor, and the one I have chosen to debug build process. You need the "If Exist" stuff in there because if the file has not been rebuilt since the last time, del will return an error and Visual Studio will stop the build. Feel free to install a unix-like rm tool and use "rm -f". If someone knows how to tell MSBuild to rebuild one specific file, this step wouldn't be needed, so I'm all ears.

    Make sure to enable "Only Build Startup projects and dependencies on Run" in Options | Projects and Solutions | Build And Run.

    Now, whenever I want to debug my custom processor, I simply set the ContentPipelineTest project as the Startup project, and hit F5. The pre-build step will delete the output file for one of the source content files, and therefore guarantee that the file has to be rebuilt. Then, the Debug external app runs MSBuild on the content subproject, notices that a file needs rebuilding, and proceeds, stopping at my breakpoints and letting me debug the content processor for my file cleanly.

    Once I am happy with the content processor, I simply switch the Startup Project to my game project and hit F5. A small annoyance is that if I ever hit Ctrl-Shift-B to build the solution, it builds all projects regardless of the above setting, and will also do the post-build step and delete that xnb file. F5 works fine. You can also unload the content test project, or unselect it from the Configuration Manager until you need to debug your content pipeline again.

    Hope this helped. If you follow this method, make sure to carefully check that each path you set is really correct, because it is hard to get good diagnostics when setting external tools like MSBuild. That was the source of my problems in the post above.
  • 11-25-2007 2:53 PM In reply to

    Re: Debugging Content Pipeline in 2.0

    We actually have most of these steps in our documentation. If you read the topic on "How to: Write a Custom Importer and Processor", it explains how to do it.

    As for forcing a build each time, you don't need pre- and post-build steps. Just specify "/p:CleanBuild=true" as a command-line argument to msbuild.exe, your startup executable.

     

    Stephen Styrchak | XNA Game Studio Developer
  • 11-25-2007 8:46 PM In reply to

    Re: Debugging Content Pipeline in 2.0

    The information about debugging a custom content pipeline is in the "Game Content Project", as I noted in my first post, not in the "How To" (which I agree is where it should really be). I found that information to be too terse. It did point me in the right direction, though, but working out things like the correct paths for MSBuild and such took a while. Maybe I'm just doing something wrong: why do I have many different MSBuild.exe files in my hard drive, none are in the PATH, and some of them don't work for this? Why can you simply write projB.contentproj but I have to fiddle with the Working Directory or specify full paths? It would be great if this documentation could be extended a bit for the final release; maybe one of the sample projects with content processors could include a debugging setup?

    Is there a way to add a reference to an existing asset file without having that file copied over to the folder for new project? Unless I can do that, I would prefer to avoid having a separate content project, and use the content project for my game, because then I don't want to keep two copies of the exported asset file and other files it may need (textures, effects, etc. ). That's why I used an Empty Project instead of the suggested game project. However, I don't know how to tell MSBuild to only rebuild one specific asset file instead of the entire content project.


    Thanks,
  • 11-25-2007 9:44 PM In reply to

    Re: Debugging Content Pipeline in 2.0

    To debug a content processor, you don't need multiple projects. Do this:

    1) Set up your project as usual. Make sure the content processor builds with debug information.
    2) Open a second copy of visual studio 2005 pro.
    3) In that copy, use "attach to process" to attach to the version of visual studio that has the XNA project open. Note that no explicit project file is needed!
    4) In the second copy of visual studio, open up the source file for your processor, and set breakpoints where you want them. Note that no explicit project file is needed!
    5) Now, build a piece of content in the original project. The content processor will break into the second copy of visual studio when you get to a breakpoint.

    If you don't have Pro, then you have to use the CLR debugger, and you probably have to add a function call to break into the debugger instead of using breakpoints.

    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
  • 04-27-2008 12:51 PM In reply to

    Re: Debugging Content Pipeline in 2.0

    If you're using VS 2005 pro just put this line in your content processor code:

    System.Diagnostics.Debugger.Launch();

    This will launch a new VS project and let you step through the code.

Page 1 of 1 (8 items) Previous Next