Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure web.config per environment

I have a Azure project (Azure 1.3) in VS2010. There are 2 webroles, one web page project and one WCF project. In debug mode I want the web project to use a web.config for DEV enviroment, and when publishing the web.config for PROD must be used.

What is the best way to do this ?

Currently I am facing issues when using a Web.Debug.config with transform XSLT. It doesn't seem to work in Azure....

like image 576
Patrick Peters Avatar asked Jan 19 '11 11:01

Patrick Peters


People also ask

How do you create a Web config for different environments?

In order to create the web. config transformations, locate the web. config file in the ASP.NET project, and right-click the item in the solution explorer. Notice the menu item “Add Config Transforms”.

How many configuration files can an asp.net project have?

There is no restriction to use the web. config file in the asp.net web application. You can have 1 Web. config file per folder .


2 Answers

Solve your problem a different way. Think about the web.config always being static and never changing when working with Azure. What does change is your ServiceConfiguration.cscfg.

What we have done is created our own configuration provider that first checks the ServiceConfiguration.cscfg and then falls back to the web.config if the setting/connection string is't there. This allows us to run servers in IIS/WCF directly during development and then to have different settings when deployed to Azure. There are some circumstances where you have to use web.config (yes, I'm referring to WCF here) and in those cases you have to write code and create convention instead of storing everything in web.config. I have a blog post where I show an example of how I did this when dealing with WIF (Windows Identity Foundation) and Azure.

like image 135
Aaron Weiker Avatar answered Oct 02 '22 14:10

Aaron Weiker


I agree with Mose, excellent question!

Visual Studio 2010 includes a solution for this type of problem, web.config transforms. If you look at your web role you'll notice it includes Web.Debug.config and Web.Release.config along with the traditional web.config. These files are used to transform the web.config during deployment.

The canonical example is "I need different database connection strings for development and release" but it also fits your situation.

There is an excellent blog post from the Visual Web Developer Team that explains how to use this feature (don't bother with the MSDN docs, I know how it works and still don't understand the docs). Check out http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

like image 22
Marc LaFleur Avatar answered Oct 02 '22 13:10

Marc LaFleur