MixedRealityToolkit-Unity
MixedRealityToolkit-Unity copied to clipboard
DEVELOPMENT_BUILD Symbol injection
Describe the bug
DEVEMOPMENT_BUILD is set in buildinfo but not used in the compilation
To reproduce
Create any code inside the bock
#If DEVELOPMENT_BUILD Debug.Log("Hello world"); //any functionality #endif
Steps to reproduce the behavior:
- Go to 'Build Window'
- Click on 'Appx Build Options'
- Scroll down to 'Build Configuration'
- Select 'Release'
- Create the vsprojet
- Launch the appx on the hololens2
- See error: 'You don't see the code inside #If DEVELOPMENT_BUILD #endIf
Expected behavior
I expect to see the effect of the code inside the block
Screenshots
If applicable, add screenshots to help explain your problem.
Your setup (please complete the following information)
- Unity Version 2020.3.41
- MRTK Version 2.7.3
Target platform (please complete the following information)
- HoloLens 2
Additional context
I am trying to add some development code inside #If DEVELOPMENT_BUILD #endif
I've seen that MRTK uses it's own buildpipelne, so EditorUserBuildSettings.development is not used in this custom buildpipeline.
The main class is this UnityPlayerBuildTools https://github.com/microsoft/MixedRealityToolkit-Unity/blob/main/Assets/MRTK/Core/Utilities/BuildAndDeploy/UnityPlayerBuildTools.cs
In this class, you define different symbols and settings.
Regarding DEVELOPMENT_BUILD, you have two blocks that might affect the symbol
if (buildInfo.HasAnySymbols(BuildSymbolDebug))
{
buildInfo.BuildOptions |= BuildOptions.Development | BuildOptions.AllowDebugging;
}
This first one works perfectly. If the buildconfiguration is selected as "debug", DEVELOPMENT_BUILD is defined
The second block is the following:
if (buildInfo.HasAnySymbols(BuildSymbolRelease))
{
// Unity automatically adds the DEBUG symbol if the BuildOptions.Development flag is
// specified. In order to have debug symbols and the RELEASE symbols we have to
// inject the symbol Unity relies on to enable the /debug+ flag of csc.exe which is "DEVELOPMENT_BUILD"
buildInfo.AppendSymbols("DEVELOPMENT_BUILD");
}
So, if the build configuration is "release", you inject manually "DEVELOPMENT_BUILD"
But when I create the project on "release", actually "DEVELOPMENT_BUILD" is not defined.
My guessing is that buildInfo.AppendSymbols("DEVELOPMENT_BUILD"); is done on line 76, but PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, buildInfo.BuildSymbols) is done before, in line 57
https://github.com/microsoft/MixedRealityToolkit-Unity/blob/476b77438442c4aff25d3a569d3c9fe90c0c6ce9/Assets/MRTK/Core/Utilities/BuildAndDeploy/UnityPlayerBuildTools.cs#L76
https://github.com/microsoft/MixedRealityToolkit-Unity/blob/476b77438442c4aff25d3a569d3c9fe90c0c6ce9/Assets/MRTK/Core/Utilities/BuildAndDeploy/UnityPlayerBuildTools.cs#L57
UnityPlayerBuildTools has changed in 2.8.2 and 3.0 but I don't see any major differences regarding this
So my questions are:
- Should DEVELOPMENT_BUILD be defined on the application on release configuration, taking into account line 76? Maybe PlayerSettings.SetScriptingDefineSymbolsForGroup should be moved after all symbols have been added to buildinfo
- If it is not an error and buildInfo.AppendSymbols("DEVELOPMENT_BUILD") is deliberately added after SetScriptingDefineSymbolsForGroup , what is that line for? I don't see any use in any part of the code after adding it
- What would be the recommended approach for defining that symbol? Debug configuration enables other things, like the "attach to debugger" window
Thank you