Home > Software design >  Xamarin forms; Conditional Compilation Symbol not working from MSBUILD command line
Xamarin forms; Conditional Compilation Symbol not working from MSBUILD command line

Time:11-16

I have a Xamarin Forms Project for iOS and Android. The solution has four configurations, Test - Debug, Test - Release, Production - Debug, Production - Release.

The shared (PCL) project has a conditional compilation Symbol for the two Test configurations, TEST. Same for Production configs and PROD

enter image description here

When I execute from Visual Studio via the debugger, the conditional compilation, which happens in the PCL's startup function (App.cs), works as expected in all four configurations:

#if TEST
            CurrentAppFlavor = Flavor.Test;
#else
            CurrentAppFlavor = Flavor.Production;
#endif

However; When I build this same project via Azure Devops Pipelines, despite selecting the correct build configuration in msbuild (and logs bear this out), the packaged builds execute as if the conditional compilation symbol does not exist (and thus default to production.)

    inputs:
      projectFile: '**/*droid*.csproj'
      outputDirectory: '$(outputDirectory)'
      configuration: '$(buildConfiguration)'
      msbuildVersionOption: '16.0'
      msbuildArguments: |
        /t:SignAndroidPackage /p:AndroidKeyStore="True" ... (additional signing vars)

I've confirmed the correct build configuration is selected (mostly because invalid configurations appear as an error) but the resultant binaries are not behaving as expected. The only thing I can think of that's different by building via command line is we are building a specific project and not in a solution. But perhaps I'm using conditional compilation symbols wrong? do I need to specify the compilation symbols on the command line, even though they're defined in the csproj's specifically? Any help is appreciated!

CodePudding user response:

Turns out that in the PCL project, my DefineConstants were restricted to AnyCPU builds; and at build time the XamariniOS task in Azure Devops builds for /p:Platform=iPhone. Why the constant worked when debugging locally I'm unsure, because the build debugging locally should have been iPhoneSimulator not AnyCPU.

  • Related