Skip to content

MonoGame Content Processing

tomspilman edited this page Jun 21, 2012 · 39 revisions

NOTE: This is preliminary documentation of a feature in progress for MonoGame3... it does not apply to 2.5!

Introduction

MonoGame like Microsoft XNA depends game content being processed at build time to an optimal format for runtime use.

Since at this time MonoGame does not have an independent implementation of the XNA content pipeline we depend on Microsoft's implementation on Windows to build content for non-Microsoft platforms. This means you must have a Windows system available to run the content pipeline regardless of what platform you're developing for.

The process requires some hand editing of your game project and some simple changes to your content project.

Game Project

In Microsoft XNA the game project controls the execution of content building. For MonoGame we follow the same rule with some simple workarounds for non-Windows platforms.

Windows and VS2010

If you're targeting MonoGame for Windows you can simply add the content project to your existing solution just like you do in any other XNA project.

Then you then edit your game project to <Import> the MonoGame content pipeline target file and include the <MonoGamePlatform> property set to Windows:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
   <Import Project="$(MSBuildExtensionsPath)\MonoGame\MonoGame.ContentPipeline.targets" />
   <PropertyGroup>
      <ProjectGuid>{2CAE49BD-8B39-42BE-A010-D3E62657000E}</ProjectGuid>
      <ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
      <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
      <MonoGamePlatform>Windows</MonoGamePlatform>

Note that above we assume that MonoGame.ContentPipeline.targets has been installed to the MSBuild extension path. If you're using source control you can just as easily have it point to a relative or absolute path to where MonoGame/MonoGame.ContentPipeline/MonoGame.ContentPipeline.targets is checkout on your system.

Windows 8 and VS2012

Microsoft has at this time not shipped the XNA Studio bits for Visual Studio 2012 (they are due around August 2012). For the moment you must install VS2010 and the Windows Phone 7 SDK on Windows 8 and use a dummy XNA project to execute the content project.

Like for the Windows build instructions above you edit the dummy game project to <Import> the MonoGame content pipeline target file and include the <MonoGamePlatform> property set to Windows8.

Non-Windows Platforms

On these platforms the recommended solution is to use a dummy XNA project which executes the content build process. You can either make one dummy project per-platform and put the <MonoGamePlatform> property to either the main <PropertyGroup> or use a single dummy project with a different <MonoGamePlatform> property in each configuration <PropertyGroup>.

Content Project

You should use a standard Microsoft XNA Content Project for MonoGame content.

In the content project you need to add a reference to the 'MonoGame.ContentPipeline.Processors' assembly which contains all the platform specific content processors. You then select the correct MonoGame version of the XNA content processors you're already using.

Note these processors will fall thru to normal XNA behavior if you're not building for MonoGame, so its safe to use them in your Xbox or Windows Phone projects as well.

MonoGame Texture

MonoGame SpriteFont

MonoGame Effect

MonoGame SoundEffect

MonoGame Song

Custom Content Processors

If you happen to use a custom content processor for your game it may depends on platform specific content like textures or sound effects. It is just as simple for you to reference the MonoGame content processors to get content optimized for your target platform.

You simply reference the 'MonoGame.ContentPipeline.Processors' assembly from your project and add code like this:

if (ContentHelper.GetMonoGamePlatform() == MonoGamePlatform.iOS)
   textureProcessor = typeof(MGTextureProcessor);
else
   textureProcessor = typeof(TextureProcessor);

Clone this wiki locally