Visual Studio graphics content pipeline for C# projects

In this post we will look at how to use the graphics content pipeline for C# in both Visual Studio 2012 and Visual Studio 2013 for Desktop and Windows Store apps.

Since Visual Studio 2012 there has been a new graphics content pipeline and graphics debugger – including a DirectX frame debugger and  HLSL debugger. The graphics content pipeline provides a number of build targets for converting common 3D and graphics assets into a usable format for DirectX applications, this includes the compilation of common mesh formats such as Collada (.dae), AutoDesk FBX (.fbx), and Wavefront (.obj) into a compiled mesh object (.cmo) file, and converting regular images into .DDS files.

Unfortunately the graphics content pipeline tasks don’t work out-of-the-box with C# because the MSBuild targets are not compatible.

Graphics content pipeline for C#

Luckily it is quite simple to get this to work for our C# projects by making a few minor tweaks to the target XML definitions. These build targets are defined in files named *Task.targets within the directories

  • C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\VsGraphics
    OR
  • C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\VsGraphics

You can download the updated graphics content tasks that work with C# projects for Visual Studio 2012 and Visual Studio 2013 for both Desktop apps and Windows Store apps from here.

After extracting the contents of the archive we can use the content tasks by right clicking our project in the solution explorer and select Unload Project, then select  Edit <yourprojectname>.csproj. At the end of the project file insert the following:

<Project ...>
...
  <Import Project="ImageContentTask.targets" />
  <Import Project="MeshContentTask.targets" />
  <Import Project="ShaderGraphContentTask.targets" />
</Project>

Reload your project, select a graphics resource such as a 3D model and then apply the appropriate Build Action, as shown in the following screenshot.

MeshContentTask - graphics content pipeline for C#

This will result in a Character.cmo file being generated in the project’s build output directory.

Controlling the graphics content pipeline task properties

In order to pass through options to the task for C# projects it is necessary to edit the associated *.props file. This contains a section for default settings. For example the ImageContentTask allows you to determine whether or not to generate mip levels. The following XML shows the available ImageContentTasks parameters found in ImageContentTask.target


<ImageContentTask
Source = "%(ImageContentTask.Identity)"
ContentOutput = "%(ImageContentTask.ContentOutput)"
Compress = "%(ImageContentTask.Compress)"
GeneratePremultipliedAlpha = "%(ImageContentTask.GeneratePremultipliedAlpha)"
GenerateMips = "%(ImageContentTask.GenerateMips)"
TLogDir = "$(ProjectDir)obj\$(ConfigurationName)"
IsDebugBuild = "$(UseDebugLibraries)"
 />

And the following XML extract shows the appropriate section within ImageContentTask.props that you would need to update.


<ImageContentTask>
 <!--Enter Defaults Here-->
<ContentOutput Condition="'%(ImageContentTask.ContentOutput)' == '' and !$(DefineConstants.Contains('NETFX_CORE'))">$(OutDir)%(RelativeDir)%(Filename).dds</ContentOutput>
<ContentOutput Condition="'%(ImageContentTask.ContentOutput)' == '' and $(DefineConstants.Contains('NETFX_CORE'))">$(OutDir)AppX\%(RelativeDir)%(Filename).dds</ContentOutput>
</ImageContentTask>

You can download the updated graphics content tasks that work with C# projects for Visual Studio 2012 and Visual Studio 2013 for both Desktop apps and Windows Store apps from here.

2 thoughts on “Visual Studio graphics content pipeline for C# projects”

  1. Thanks allot!

    now , to decide if SlimDX and Win2d might be redundant.

    .WPF and SL have a lot of 3rd party stuff… if only SL could use shader model at least 3, bonus 4, 5..

    Im wondering if it can be built , and still support OSX.. will look at EXEn maybe..

    I use SVG, XAML, c# and c++ if i have to.. and HLSL..

Leave a Reply