Use multiple environments in .NET Framework 4.7.2

Viewed 893
1 Answers

I don't think there's a simple/supported way of getting the settings filename override functionality that NET core has for .Net Framework because it doesn't have or use environment variables and projects/executables in the same way.

But there is a library called Slow Cheetah that seems to do this, which allows you to automatically transform your app.config (or any file) when you press F5 in Visual Studio

I ended up using a single App.config file with different keys - see below.

From here, you'll just need to work out your own trigger for determining your Dev/Prod etc environment - probably a build step.

(In my case, I had a ClickOnce app that was either published/prod or not/dev - so this part was easy)

<connectionStrings>
  <add name="Dev"
connectionString="..." />
  <add name="Prod"
connectionString="..." />
</connectionStrings>
Related