开发者

Azure web.config per environment

开发者 https://www.devze.com 2023-02-05 06:03 出处:网络
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 publ

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.co开发者_StackOverflow社区nfig with transform XSLT. It doesn't seem to work in Azure....


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.


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


I like this question !

For worker roles, I solved this problem by detecting the environment at runtime and launching my 'application' in a new AppDomain with a custom configuration :

  • bot.cloud.config
  • bot.dev.config
  • bot.win.config

This is incredibly efficient !

I'd like to do the same with web projects, because using the Azure specific configuration is a lot of trouble :

  • Both config are not in the same place, which is time-consuming when debugging
  • You have to learn a new way of writing something that sould be standard
  • Sometime you'll wonder if the app falled back on web.config because of a stupid syntax error

I'm still searching the right way to do that, like in this post


Another possible solution is to have two CloudService projects, each one with specific ServiceConfiguration.cscfg(dev/prod). Develop using the Dev, but deploy the Prod.


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

It depends on whether you want to make it work on your local machine or inside continuous integration.

  • For the local machine I tried to answer here: https://stackoverflow.com/a/9393533/182371
  • For the continuous integration it's even easier. When you build from the command line specifying the Configuration property value your configs WILL be transformed (no matter what it does when you build inside VS). So properly specifying build configurations for both cloud and web project will give you the correct output depending on build parameters.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号