1

We are currently working on a Xamarin Forms (.NET Core) application. We use Microsofts DevOps for the code repo, building and deployment.
Since we want to test newly developed features in a safe testing environment, we need to configure the app before building. At the bare minimum we need to swap out the backend uri (e.g. one for testing and one for production).

We thought about using pre-compiler flags, but we would like to keep the configuration away from the code if possible.

Is there an elegant solution or a best practice for handling that?

  • is your build creating the android/iphone package? are you using config files to store these variables or something else? – Ewan Aug 21 '19 at 07:57
  • Yes the build creates the respective Android/iPhone/Uwp package. For now the variables are static strings in the code. – Manuel Merzinger Aug 21 '19 at 07:59

1 Answers1

0

It's been a while since I did Xamarin, but I believe the approach I used was to have a configuration file as an asset.

Your build steps can modify the configuration file as required pre build and package

Your code then parses the asset text and reads out the configuration values.

This isn't really any different from compiler macros though. Maybe a bit neater if you have large blocks of config.

Alternately, If you app logs on, you can have the login api return settings for the user. Although obviously you now have a hardcoded login url.

Ewan
  • 70,664
  • 5
  • 76
  • 161
  • After a bit more research we came to the conclusion that your idea is probably the closest we could get to having proper environment variables. The only issue are the Pre-Compiler Flags, they are a bit cumbersome to handle, but better than everything else. So we based our approach on your idea, Thank you! – Manuel Merzinger Sep 26 '19 at 11:25