Shawn Hargreaves Blog
One of the biggest differences between the XNA content pipeline and the way many people are used to loading their game assets is that with the content pipeline, games no longer read directly from standard asset formats like .X, .BMP, and .FX. Instead, we process those files into a specialized binary format at the same time as compiling your game code.
The idea of processing assets during the build will be familiar to anyone who has worked on a console game, but may come as a surprise to people from a Windows background. There are actually several reasons why this is a good idea:
But what if you need to convert content yourself, outside of XNA Game Studio Express? For instance what if you want to use the content pipeline in a level editor, or to convert user provided assets so that modders can extend your game?
You're in luck, because all the content pipeline build functionality is exposed as an MSBuild task. I won't go into details about MSBuild here (you can find more about it on MSDN, or using Google), other than to explain that MSBuild runs tasks as described by XML project files. In fact the .csproj files that you load into Game Studio Express are just a special kind of MSBuild project.
So to manually build content, you simply have to generate an MSBuild project that invokes the content pipeline, run it using MSBuild, and then load in the compiled .xnb files that will have been created for you.
Here is an example MSBuild project that uses the content pipeline to build a single file called MyTexture.tga:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <UsingTask TaskName="BuildContent" AssemblyName="Microsoft.Xna.Framework.Content.Pipeline, Version=220.127.116.11, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d" /> <PropertyGroup> <XnaInstall>C:\Program Files\Microsoft XNA\XNA Game Studio Express\v1.0\References\Windows\x86</XnaInstall> </PropertyGroup> <ItemGroup> <PipelineAssembly Include="$(XnaInstall)\Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll" /> </ItemGroup> <ItemGroup> <Content Include="MyTexture.tga"> <Importer>TextureImporter</Importer> <Processor>SpriteTextureProcessor</Processor> </Content> </ItemGroup> <Target Name="Build"> <BuildContent SourceAssets="@(Content)" PipelineAssemblies="@(PipelineAssembly)" TargetPlatform="Windows" /> </Target> </Project>
If you save this XML into a file called test.proj, you can then run this from the commandline by invoking "msbuild test.proj".
The whole Content Pipeline is a very good idea ! Nice work.
I'm working on a tool based on XNA that needs to load resources such as fbx files and convert them into the appropriate pipeline objects from code. I've been able to load an fbx file using FbsImporter, but I'm unable to convert the file to a model or xnb file. Is creating an msbuild script the only way to convert between an fbx file and xnb or can I do it all in code. If it is the only way, is it possible to do the build task without creating the script on disk?
Currently the only way to access this functionality is via the BuildContent MSBuild task.
You can do this entirely in memory, though, using the Engine object and associated classes from the Microsoft.Build namespace. That lets you build up a project in memory as an object model, then pass it to an Engine that will build it for you.
I'm in the same position as Milow. Does the XNA redistributable provide everything needed to get the above solution working on computers that do not have the XNA framework installed?
The framework redistributable doesn't include any of the content pipeline functionality. This is currently only available by installing the full product.
Way back in November I blogged about how to use MSBuild to run your own content build, bypassing the
As I wrote the other day, I'd like to help out people that are having trouble understanding the content
Is it possible to build content at runtime? For example, I copied a media file over to my XNA application's content folder, and then created an instance of WmvImporter:
WmvImporter videoImporter = new WmvImporter();
I then tried to import and build the content for my XNA app using the Import() method:
VideoContent videoContent = videoImporter.Import(filename, new ContentImporterContext());
However, I cannot instantiate an instance of ContentImporterContext because it has no constructor, but I need an instance of the class to pass as a parameter to the Import() method.
How should I accomplish this?
Derrick: check out the WinForms Content Loading sample on creators.xna.com
Hi Shawn, I'm working on an Editor for my XNA game engine, using Visual Studio Shell. I'm basically trying to replicate Game Studios' Content Projects.
But when I add the UsingTask element to my project file, VS throw an error when trying to create a new project:
"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure Microsoft.VisualStudio.Package.SecurityWarningDialog.resources was correctly embedded or linked into assemblyMicrosoft.StoryboardDesigner.ProjectBase at compile time, or that all the satellite assemblies required are loadable and fully signed."
I have no clue what kind of resource it's talking about. Any ideas ?
Basically I'm trying to build an .fbx model with MSBuild following the example you have above and I get:
error MSB4062: The "BuildContent" task could not be loaded from the assembly Microsoft.Xna.Framework.Content.Pipeline, Version=18.104.22.168, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d. Could not load file or assembly 'Microsoft.Xna.Framework.Content.Pipeline, Version=22.214.171.124, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d' or one of its dependencies. The system cannot find the file specified.
I've put ToolsVersion="4.0" in the Project header.
I've installed the latest everything (XNA GS, .NET 4.5, VS Express 2010 SP1)