Hi all,
I need to use different api endpoints based on if the app is for testing or production. I am using app center and have configured environment variables there, with required values.
The question is, how can I assign the value of variable to be used in the application?
Hi @gvuksa, see the repo https://github.com/Microsoft/appcenter-build-scripts-examples
This repo contains many examples about how to improve our build scripts to turn our app more dynamically in build time.
I guess that "Change app constants" script maybe help you.
Answers
Hi @gvuksa, see the repo https://github.com/Microsoft/appcenter-build-scripts-examples
This repo contains many examples about how to improve our build scripts to turn our app more dynamically in build time.
I guess that "Change app constants" script maybe help you.
Ah, and if you have a new idea for custom build script, share for us in this open source project
Hi @ionixjunior, this works for shared projects, but I can't make it work with .net standard library.
I have a bash script in the root of android project with namespace "Root.Droid"
I have a configuration class called Configuration.cs in the .net standard library with default namespace "Root" and in the Helpers folder of that library. So, the namespace of Configuration.cs is Root.Helpers. I have also tried adding helpers folder with Configuration.cs file in the Android project.
I have made this small change to the bash script to echo "$APP_CONSTANT_FILE is not found", and it always echoes this. Do you know how can I point to the Configuration.cs file in this case?
Sorry, if someone needs I have resolved this. There are three folders before the .net standard library from the solution url. So proper app constant file is:
where "Root" is Root namespace of your project / folder structure from .sln file.
Nice!
You can use the Microsoft.Extensions.Configuration framework for this - That way you don't need to rebuild:
Hi @martinfletcherw2gd
Just need some clarification. is it necessary to add configuration files? I just want to read custom environment variable that's passed from Build settings of App in App Center. I don't want to use any custom build script.
I am trying following code but it's not working.
EnvironmentVariablesConfigurationProvider env = new EnvironmentVariablesConfigurationProvider();
env.TryGet("AppClientID", out string appclientId);
here appClientId is null.
could you please help?
Hi @NirajBhatt
As far as I know you use EnvironmentVariablesConfigurationProvider only in asp.net Core.
Anyway, environment variables should be extracted before the build process, I don't think that you can access them after the build if you haven't added their values to one of your project files.
App center documentation only mentions build scripts, xml files (with example to connect to private NuGet feed), and build gradle for Android.
https://docs.microsoft.com/en-us/appcenter/build/custom/variables/
I haven't had a chance to try Microsoft.Extensions.Configuration as mentioned by @martinfletcherw2gd , but simply updating variables using bash as provided in the accepted answer works great. Just pay attention that the regex part in sed is set properly for specific variable that you need.
Sorry for late reply @gvuksa ,
Thanks for information. I ended up using Mobile.BuildTools (https://github.com/dansiegel/Mobile.BuildTools)