[SOLVED] Conditional compilation of pipeline Content based on Visual Studio project / platform

If you’re building from source, I believe you should be able to do some editing to the Content Builder targets file to change the “platform” argument that gets passed to MGCB.exe, which is the executable that actually builds the content when running your Visual Studio build.

The file should be located in your MonoGame install directory under the MonoGame.Framework.Content.Pipeline directory. As an example, my file is located at:
D:\solari\code\external\MonoGame-3.7.1\MonoGame.Framework.Content.Pipeline\MonoGame.Content.Builder.targets

If you look in this file, you’ll notice the Header section, which defines the /platform argument that gets passed when building content. By default, it uses the MonoGamePlatform variable, but you should be able to change that to be either “Windows” or “DesktopGL” based on your Visual Studio project configuration (I think it would be $(Platform) and then you would just have to be sure to send the correct monogame platform based on your Visual Studio build configuration if they’re not a 1-1 match)

Alternatively, you could decouple the default way content is built by removing your Content.mgcb from your Visual Studio project, and instead adding a build event in your VS project which would call MGCB.exe with the correct arguments. Note that MGCB in the command line can be a little finicky, but check out this other thread of mine with a working example of passed arguments: here

If you’re not building from source I’m not sure of any way to do this automatically. You will likely need to deal with multiple content files. If this ends up becoming troublesome or error prone, check this out. Another MG community member was looking into a way of auto generating the Content.mgcb files based on existing files in a given directory. I haven’t looked at it yet, but was planning on checking it out in the future for our current project.