0

So, I have a .net project with an App.config file that's supposed to be filled, amongst other things, with an API key.

As an example:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="ApiToken" value="YOUR_API_TOKEN_HERE" />
    </appSettings>
</configuration>

This is what is committed into the VCS for reference and to automatically build MyApp.dll.config.

However, when I'd developing and debugging, it would be useful for me to have a local version of the file with the secrets filled in.

How can I achieve this?

Note: I would prefer this file-based approach to environment variables.

Rui Oliveira
  • 606
  • 8
  • 20
  • Maybe I don't understand your question right, but why don't you just create such a file and place it where your config file qould normally be read by your app? – Sigmarod Mar 07 '23 at 10:49
  • The build process automatically generates the `MyApp.dll.config` from the "source" file `App.config`. Won't it be replaced every build? Yes it will, I have tested. – Rui Oliveira Mar 07 '23 at 10:51
  • I mean you could try to replace your "source" App.config for the development process, just be careful to not commit it. – Sigmarod Mar 07 '23 at 10:53
  • Create a configuration for local development, set up configuration specific transforms for your config file https://www.hanselman.com/blog/slowcheetah-webconfig-transformation-syntax-now-generalized-for-any-xml-configuration-file. Exclude the local development config file from source control in .gitignore. – Jodrell Mar 07 '23 at 10:54
  • Does this answer your question? [Transform app.config for 3 different environment](https://stackoverflow.com/questions/20690452/transform-app-config-for-3-different-environment) – Vadim Martynov Mar 07 '23 at 10:55
  • You might consider creating an interface for configuration instead of taking a dependency directly on ConfigurationManager. When debugging, you inject an implementation that provides test values. When deployed, you inject an implementation that uses ConfigurationManager. This way you could even bring in settings from anywhere else, like env variables, etc. – Crowcoder Mar 07 '23 at 12:07

0 Answers0