Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a different web.config file for each Azure deployment slot?

Tags:

asp.net

azure

I have several Azure deployment slots: dev, staging, production, etc.

I want to create a set of web.config files, one for each deployment slot. So web-dev.config, web-staging.config, etc.

I do not want to use the slot-specific settings in Azure because if you have more than one or two settings it seems vastly easier to just have all your settings in a text file.

I do not want to write XML transforms on a single web.config file because that is insane. Config files already have enough complexity without an extra layer of indirection. And even if I didn't think that, web.config transforms seem to be tied to build configuration and not to a deployment destination. I don't want to contort my build process for the benefit of my deploy process.

I know copying and pasting config settings across files is gross but here we are. Until someone at MS fixes configuration in ASP.net, I just want to have one file for each deployment destination and call it a day.

How do I do it?

like image 403
John Shedletsky Avatar asked Sep 28 '22 08:09

John Shedletsky


1 Answers

You have a few options.

The most obvious is the transformations. I don't know why you're so quick to discount it: only a few settings should be changing between environments, right?

Or you can have multiple .config files and then make it part of your deployment script (I hope you're not just using VS to deploy). Your scripts can select the correct file and rename it to web.config.

And of course, you can move all the app settings and connection string stuff, and probably more, out of the web.config file and use alternative configuration systems. Perhaps a giant XML or JSON file with all the settings for each environment in it. Or perhaps use environment variables.

Really, it's up to you to write your deployment scripts and set your configuration up how you want it. It's not "up to Microsoft", it's up to you, though they have made it even easier to use a common configuration system across multiple sources in ASP.NET 5.

like image 175
mason Avatar answered Oct 13 '22 00:10

mason