Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MAUI Best method of setting the configuration per environment

Tags:

.net-core

maui

So I have a MAUI app with a lifecycle config of the following

  1. Dev machine config
  2. Dev environment config (early preview)
  3. Staging (UAT) config
  4. Production (Live) config

Question: How do I configure the app as it switches between stages

How do I know the app is in e.g.

  • Android internal testing and the config should point to the dev environment
  • Android Open testing and the config should point to the staging environment
  • Android Production and the config should point to the Production environment
  • IOS internal testing and the config should point to the dev environment
  • IOS Open testing and the config should point to the staging environment
  • IOS Production and the config should point to the Production environment

To elaborate, I would like to build the package once and deploy that package to multiple environments, with the configuration of that package changing based on the environment it is being deployed to

Cheers all

like image 212
Steve Parry Avatar asked Oct 31 '25 18:10

Steve Parry


1 Answers

Indeed, you wouldn't want mixing up the development version of your app with the production one. Fortunately, you can target different environments through multiple project configurations.

For example, you could have DEV, TEST & PROD configurations. To do this, open your *.csproj file and add following snippet:

<Project Sdk="Microsoft.NET.Sdk">
...
    <PropertyGroup>
        <Configurations>DEV;TEST;PROD</Configurations>
    </PropertyGroup>
</Project>

And from there, you can customize the project configuration in your *.csproj file for each of the targeted environments, accordingly to your needs:

<Project Sdk="Microsoft.NET.Sdk">
...
    <PropertyGroup Condition=" '$(Configuration)' == 'DEV' ">
    </PropertyGroup>
    
    <PropertyGroup Condition=" '$(Configuration)' == 'TEST' ">
    </PropertyGroup>
    
    <PropertyGroup Condition=" '$(Configuration)' == 'PROD' ">
    </PropertyGroup>
</Project>

This can be relatively long and complex, so if you want, you can read a complete walkthrough example that I made on this to guide you through it.

like image 151
Kapusch Avatar answered Nov 04 '25 22:11

Kapusch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!