microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

DEVELOPMENT_BUILD Symbol injection #11246

Closed Maesla closed 9 months ago

Maesla commented 1 year ago

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:

  1. Go to 'Build Window'
  2. Click on 'Appx Build Options'
  3. Scroll down to 'Build Configuration'
  4. Select 'Release'
  5. Create the vsprojet
  6. Launch the appx on the hololens2
  7. 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

image

If applicable, add screenshots to help explain your problem.

Your setup (please complete the following information)

Target platform (please complete the following information)

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("DEVELOPMENTBUILD"); 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:

  1. 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
  2. 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
  3. What would be the recommended approach for defining that symbol? Debug configuration enables other things, like the "attach to debugger" window

Thank you

IssueSyncBot commented 9 months ago

We appreciate your feedback and thank you for reporting this issue.

Microsoft Mixed Reality Toolkit version 2 (MRTK2) is currently in limited support. This means that Microsoft is only fixing high priority security issues. Unfortunately, this issue does not meet the necessary priority and will be closed. If you strongly feel that this issue deserves more attention, please open a new issue and explain why it is important.

Microsoft recommends that all new HoloLens 2 Unity applications use MRTK3 instead of MRTK2.

Please note that MRTK3 was released in August 2023. It features an all new architecture for developing rich mixed reality experiences and has a minimum requirement of Unity 2021.3 LTS. For more information about MRTK3, please visithttps://www.mixedrealitytoolkit.org.

Thank you for your continued support of the Mixed Reality Toolkit!