Hi,
Is it possible to pass the /define parameter from the .csproj file?
I have multiple projects pointing to the same content file but I need different inclusions depending on platform. I figured the easiest way is to have preprocessor macros inside the content file and have different projects pass the preprocessor param.
If this is not possible - what’s the most elegant way of having multiple platforms share 95% of the content and have the remaining 5% separated? One common content file + an additional one per platform?
Thanks
Tom
March 23, 2016, 6:34pm
2
You would have to customize the .target file to allow you to pass whatever you want:
<!--
MonoGame - Copyright (C) The MonoGame Team
This file is subject to the terms and conditions defined in
file 'LICENSE.txt', which is part of this source code package.
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="MonoGame.Build.Tasks.CollectContentReferences" AssemblyFile="MonoGame.Build.Tasks.dll" />
<!-- Add MonoGameContentReference to item type selection in Visual Studio -->
<ItemGroup>
<AvailableItemName Include="MonoGameContentReference" />
</ItemGroup>
<!-- This disables the IDE feature that skips executing msbuild in some build situations. -->
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
<Target Name="Prepare">
<PropertyGroup>
This file has been truncated. show original
Like different content files for one platform vs another?
This is a feature we really want to get into the Pipeline tool directly, but I’ve not had time to implement.
That is a reasonable option and how you would have done it in XNA if you didn’t want to hand modify the .contentproject flle.
Tom:
Like different content files for one platform vs another?
This is a feature we really want to get into the Pipeline tool directly, but I’ve not had time to implement.
Yes - mostly for shaders since they tend to be quite different on different platforms. This feature would be really cool.
I don’t really like the idea of having multiple content files so I’ll copy the .target file, edit it and reference it locally. I’ll probably just add:
/define:Platform=$(MonoGamePlatform)
That should cover my use-case without introducing many custom params.
Thanks for the tips!
I just tried tinkering with mgcb.exe and it seems there’s no /define option although the doc page mentions it. I installed the latest version (3.5) but still no luck. What am I missing?
Tom
March 24, 2016, 6:07am
5
loodakrawa:
mostly for shaders
Note you can use #ifdef
within shaders themselves. Look to see how we do it in the stock effects:
https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Graphics/Effect/Resources/SpriteEffect.fx
Notice the #include "Macros.fxh"
which is where all the helpers for tweaking shaders based on the target platform.
Hum… that command does look missing from the command line parser:
https://github.com/mono/MonoGame/blob/develop/Tools/MGCB/BuildContent.cs
The intent was for it to push a named value on to the property collection here:
https://github.com/mono/MonoGame/blob/develop/Tools/MGCB/CommandLineParser.cs#L90
Sort of like the $set
preprocessor command does:
https://github.com/mono/MonoGame/blob/develop/Tools/MGCB/CommandLineParser.cs#L264
Don’t know how this got documented, but the implementation is missing.