Search Unity

UWP build - Conditional compilation symbols are ignored in Unity projects

Discussion in 'Windows' started by DoomSamurai, Aug 1, 2017.

  1. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    Hey all,
    in a post-process build script we add a compilation symbol to the UWP Master configuration so that we can have some code run only in the Master build but not the Release build. When we used Unity 5.4.5p1 this worked properly. We recently upgraded to Unity 5.6.2f1 and now this compilation symbol is ingored in Unity projects. The compilation works as intended if I add '#if MASTER' to a class in the UWP solution (MainPage.xaml.cs or such). It just doesn't work in any of the Unity scripts that we have.

    Does anyone have some information on this behaviour? Is it intended or is it a bug? It could be related to this issue (https://issuetracker.unity3d.com/is...on-problem-with-runtimeinitializeonloadmethod) but I'm not sure since that particular issue has very little info.
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I find it interesting that you say this worked... scripts are compiled once. They are not compiled for each config (debug/release/master) separately, which means that all 3 configs will share the same preprocessor defines in scripts.

    Can you tell me more about what that postprocess script does?
     
  3. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    I forgot to mention that we build with Unity C# Projects checked.

    The post-process script simply edit the generated csproj file and adds MASTER in DefineConstants property for the relevant PropertyGroup elements. So I would get something like :

    <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Master|x64'">
    <OutputPath>bin\x64\Master\</OutputPath>
    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP;UNITY_METRO;UNITY_WSA;UNITY_UWP;UNITY_WSA_10_0;MASTER</DefineConstants>
    <Optimize>true</Optimize>
    <NoWarn>;2008</NoWarn>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <UseDotNetNativeToolchain>True</UseDotNetNativeToolchain>
    </PropertyGroup>

    When I go in Visual Studio I can see that the symbol was added in the conditional compilation symbols field in the project properties for the main project. That used to define the symbol for the Unity projects as well but now it doesn't. I tested by generating a UWP solution for an old changelist of our project with Unity 5.4.5p1 and it did work.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Perhaps the script hardcoded the location of script C# projects? They changed at some point IIRC.
     
    twobob likes this.
  5. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    I think you are right, that might be the issue. I actually can't see the MASTER symbol in the Unity projects at the moment. But it does appear in the main project. I'll investigate further.
     
  6. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    Yeah that's what the problem was, the post-process script was pointing to the previous location for the Unity projects files. That's why it worked in 5.4.5p1, this version of Unity still outputed the files in the correct location for the post-process to work correctly. Thanks Tautvydas!