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

tl;dr: If your shared Content.mgcb file has a “/platform:<some_platform>” line defined somewhere near the top, remove it. Save the file. Clean, rebuild, and redeploy your solution.


Ok, so I’ve made a discovery. I also have the correct MonoGamePlatform setting in my project files. I took a look at the targets file and everything looks like it checks out there as well. That header definition gets referenced in the command and should work.

Having said that, it looks like if a /platform line is defined in the content file, this will override the project setting. I have a suspicion that this used to not work before and was fixed in MonoGame 3.7+ because my project worked just fine until I upgraded. Afterwards, for whatever platform was not defined in the content file, it wouldn’t work, giving an exception saying “This MGFX effect was built for a different platform!”

By simply removing the “/platform” line from my content file, everything works correctly on my build again. No additional steps needed. This line probably ended up in here in the first place because back when I was creating my game project, I started with a Windows project. I then moved the content file out to a central location and linked my Windows and Android projects to that instead.

Aaaaaanyway, I think something definitely changed in MonoGame 3.7… and it actually sounds like a fix for a defect. It is kind of not obvious though that you’d have to remove this line when setting up your content file for multiple platform builds.

1 Like