Search Results for

    Show / Hide Table of Contents

    Use Preprocessor Directives

    • GitHub (AL-Go)
    • Azure DevOps

    WIP

    If you e.g. have a multi-language app, you may have the same source code as a base but need different logic depending on the target localization. For that you can use Preprocessor Directives in AL.

    You can use the Pipeline Setup Hooks to set the preprocessorSymbols in your app.json at build time to use them during the build.

    One example is to add a new property to a BC artifacts configuration in the cosmo.json:

    {
        // ...
        "bcArtifacts": {
            // ...
            "currentDE": {
                "version": "",
                "type":    "sandbox",
                "country": "de",
                //...
                "TestAppPreProcessor" : "DE" 
            }
        }
    }
    

    And in the pipeline hook read that new property and set the preprocessorSymbols in the app.json of the test app accordingly:

    OnSetupBuildTasks:
        - powershell: |
            echo 'configure preprocessor on test app'
            $config = Get-Content "$(job.SourcesDirectory)\.devops\cosmo.json" | ConvertFrom-Json  
            $preprocessorContent = $config[0].bcArtifacts.${{ variables['BC-Artifacts'] }}.TestAppPreProcessor
            $TestApp = Get-Content "$(job.SourcesDirectory)\test\app.json" | ConvertFrom-Json
            if ($preprocessorContent -ne $null) {
                $list = New-Object System.Collections.ArrayList
                $list.Add($preprocessorContent)
                $TestApp | Add-Member -Type "NoteProperty" 'preprocessorSymbols' -Value ($list)
                $TestApp | ConvertTo-Json -Depth 100 | Out-File "$(job.SourcesDirectory)\test\app.json"
            }
    
            echo $TestApp
        displayName: On Setup Build
    
    In This Article
    Back to top 2025 © COSMO CONSULT - Data protection - Imprint