1

I have a Xamarin.Forms app. As it does not have built in configuration file, I used a solution found here:

https://www.andrewhoefling.com/Blog/Post/xamarin-app-configuration-control-your-app-settings

and here

https://github.com/HoeflingSoftware/XamarinAppSettings

So now I have a custom appsettings.json file. The secrets in the file are replaced in AzureDevops pipeline. But how can I run the app from Visual Studio (on an emulator)? If it was a web application, I would use Manage User Secrets functionality, which would store the secrets in my file system. So it would be used automatically when the app is running during development. But how can I do it for a Xamarin.Forms app with its custom json file?

David Shochet
  • 5,035
  • 11
  • 57
  • 105
  • 1
    There is no `appsettings.json` in xamarin forms. If you want to secure some values within your app, you can use [Xamarin Essentials Secure Storage](https://learn.microsoft.com/en-us/xamarin/essentials/secure-storage?context=xamarin%2Fxamarin-forms). Despite that, you should keep user secrets, like api keys, safely stored in your backend. Mobile apps can be hacked and those keys can be retrieved. – FabriBertani Sep 15 '21 at 20:37
  • @FabriBertani Thank you for your comment. I need to be able to replace the values in AzureDevops, so they are different for QA and Production. The solution I gave links to allows having .json file. – David Shochet Sep 15 '21 at 20:44
  • Can you use [app secrets](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-5.0&tabs=windows)? – ste-fu Sep 16 '21 at 10:11
  • @ste-fu That is what I am trying to do, but don't see how it can be used in Xamarin.Forms. – David Shochet Sep 17 '21 at 13:32
  • https://github.com/ncarandini/XFUserSecrets – CraPo Nov 17 '22 at 11:03

1 Answers1

0

You could use the Replace Text in Source Files task on Marketplace to replace text in your source, before you build the project. You can then store the secret as a secure value in the pipeline variables library.

We use a similar approach to update the build versions for Xamarin Apps and for providing access to the Signing files.

newky2k
  • 419
  • 5
  • 12
  • Thank you for your answer. As I understand, you are talking about replacing secret values in the pipeline, but my issue is in storing secrets on my machine during development, like in Manage User Secrets functionality. – David Shochet Sep 17 '21 at 13:20