On an MVC.NET project at work, we came across the need to be able to override the web.config’s appSettings uniquely on each of our local environments. Turns out there’s a very easy way to do just that inside the web.config file.
Just add the file attribute to the
<!-- WEB.CONFIG --> <configuration> ... <appSettings file="local.config"> ... </appSettings> ... </configuration>
<!-- LOCAL.CONFIG --> <?xml version="1.0" encoding="utf-8"?> <appSettings> <add key="MySQLConnectionString" value="..." /> </appSettings>
Now when your app loads, it will check to see if there’s a local.config file relative to the web.config file. If there is a file, then it overrides any web.config settings it finds duplicates for in the local.config. If the local.config file does not exist, then it is ignored.
Pro tip: Keep local.config out of your code repo and boom! Easily manageable local dev environment settings.