Visual Studio Graphics Content Pipeline for C# Projects

Published March 24, 2014 by Justin Stenning, posted by Spazzarama
Do you see issues with this article? Let us know.
Advertisement
In this article 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#

Thankfully it is quite simple to get this to work for our C# projects by making a few minor tweaks to the MSBuild 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 that are attached to this article. 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: ... 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. [attachment=20525:MeshContentTask.png] 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 ImageContentTask parameters found in ImageContentTask.target And the following XML extract shows the appropriate section within ImageContentTask.props that you would need to update. $(OutDir)%(RelativeDir)%(Filename).dds $(OutDir)AppX\%(RelativeDir)%(Filename).dds

Conclusion

Visual Studio 2012 brought with it some significant improvements for graphics / Direct3D programming for the C++ world, however it left C# developers a little short. By integrating the graphics content pipeline with your C# project you can then make use of these great features.

Further reading

Direct3D Rendering Cookbook by Justin Stenning and published by Packt Publishing provides further examples of how to work with Direct3D in C# using SharpDX and the Visual Studio graphics content pipeline.

Article Update Log

20 Mar 2014: Initial release
Cancel Save
0 Likes 5 Comments

Comments

Cvnk
How is this different from the content pipeline that comes with XNA (which works perfectly fine with C# with no tweaking)? Is the the XNA pipeline just a wrapper for this and is it missing more advanced features, similar to how XNA well never take advantage of the latest DirectX improvements?
March 21, 2014 05:18 PM
jpetrie

These underlying .targets are newer than XNA's and may not be strongly related (other than doing the same general thing); I haven't examined them in detail.

Other than some differences in functionality, which may or may not be relevant to your individual needs, I'd say a major difference between these new .targets and XNA's pipeline is that they are still a live product (whereas XNA is at the end of its life).

March 21, 2014 08:29 PM
Spazzarama

How is this different from the content pipeline that comes with XNA (which works perfectly fine with C# with no tweaking)? Is the the XNA pipeline just a wrapper for this and is it missing more advanced features, similar to how XNA well never take advantage of the latest DirectX improvements?

These are new targets available in the vanilla VS 2012 (pro) & 2013 (express) install, other than similar behaviour and perhaps internal code reuse I don't think they are related to the XNA ones.

March 22, 2014 10:17 AM
J.K
J.K

What to do with newer versions of Visual Studio ?

August 29, 2016 06:57 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!

In this article 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.

Advertisement

Other Tutorials by Spazzarama

Spazzarama has not posted any other tutorials. Encourage them to write more!
Advertisement