Why does my content rebuild every time?

Originally posted to Shawn Hargreaves Blog on MSDN, Friday, August 14, 2009

The XNA Framework Content Pipeline tries to use incremental rebuilds wherever possible. This means if you add a hundred content files, build your project, change just one of those files, then build again, only that specific file needs to be rebuilt.

In a perfect world this would work 100% of the time, but in reality we sometimes rebuild more content than is strictly necessary. Most often this happens if you make a change to a custom processor assembly. The pipeline does not keep track of which assemblies were involved in building which pieces of content, so if any custom assembly changes, all content will be rebuilt. Unwanted rebuilds may also occur when changing project settings, if you have circular project references, or if the Content Pipeline cache file is somehow getting deleted.

If you think your content is rebuilding more often than it should, you can find out why by turning up the MSBuild output verbosity. If you rebuild-all with the Skinned Model sample, the Visual Studio output pane will normally show something like:

    Building dude.fbx -> SkinningSample\bin\x86\Debug\Content\dude.xnb 
    Building head.tga -> SkinningSample\bin\x86\Debug\Content\head_0.xnb 
    Building SkinnedModel.fx -> SkinningSample\bin\x86\Debug\Content\SkinnedModel_0.xnb 
    Building jacket.tga -> SkinningSample\bin\x86\Debug\Content\jacket_0.xnb 
    Building pants.tga -> SkinningSample\bin\x86\Debug\Content\pants_0.xnb 
    Building upBodyC.tga -> SkinningSample\bin\x86\Debug\Content\upBodyC_0.xnb 

Open the Tools / Options menu in Visual Studio. If you are using C# Express, make sure the Show all settings box is checked. Expand Projects and Solutions, select the Build and Run node, and change the MSBuild project build output verbosity setting from Minimal to Normal.

Now when we rebuild-all, the output pane shows:

    Target CoreCompile: 
        Building dude.fbx -> SkinningSample\bin\x86\Debug\Content\dude.xnb 
        Rebuilding because asset is new 
        Importing dude.fbx with Microsoft.Xna.Framework.Content.Pipeline.FbxImporter 
        Serializing obj\x86\Debug\dude_0.xml 
        Processing dude.fbx with SkinnedModelPipeline.SkinnedModelProcessor 
        Compiling SkinningSample\bin\x86\Debug\Content\dude.xnb 
        (etc)

If we make a change to SkinningData.cs, which changes the custom pipeline assembly, the next build will show:

    Target CoreCompile: 
        Rebuilding all content because pipeline assembly SkinnedModelPipeline.dll has changed 
        Building dude.fbx -> SkinningSample\bin\x86\Debug\Content\dude.xnb 
        Importing dude.fbx with Microsoft.Xna.Framework.Content.Pipeline.FbxImporter 
        Serializing obj\x86\Debug\dude_0.xml 
        Processing dude.fbx with SkinnedModelPipeline.SkinnedModelProcessor 
        Compiling SkinningSample\bin\x86\Debug\Content\dude.xnb 
        (etc)

If you find that content keeps rebuilding because assemblies are changing, consider splitting these assembles to separate game logic (which tends to change often) from content data types (which change less often). If your content project can avoid referencing your game logic assembly, it will no longer need to rebuild each time that code changes.

Blog index   -   Back to my homepage