34

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....

1
  • This SO answer gives the minimum number of steps necessary to setup Azure config transforms. Jul 21, 2011 at 21:41

5 Answers 5

10

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.

5
  • 1
    This is good advice particularly when you take into account the fact that you can change the cloud configs while the instance is running, unlike the web configs. Having said that, I also use config transforms on the web configs which saves faffing about with stuff that is difficult to move from the web.config. Jan 19, 2011 at 20:14
  • @aaron-weiker: this is a great advice for the things like appsettings, but is doesn't seem to work for example if you configure your endpoints in a different way for prod/dev environments. As long as I know, it's not possible to configure binding/endpoints through the *.cscfg. But maybe I'm wrong.
    – Nikita R.
    Feb 22, 2012 at 11:07
  • @NikitaG. Correct, you cannot change bindings at runtime. Bindings are configured as a part of the package itself and never change. If you need something dynamic, you would need to add all possible ports into your endpoint configuration and then at runtime choose the appropriate one. Not that I think this is a good idea, but it is one way to make things a little more dynamic. Feb 28, 2012 at 18:21
  • Try to create a custom configuration provider which reads the current environment key from the ServiceConfiguration (Prod/Dev) and then reads the corresponding value from you web.config "custom configuration" key: <add key="ServiceAddress" prod="www.yourservice.com" dev="dev.yourservice.com" /> etc... Aug 25, 2013 at 13:26
  • 1
    The link you provided in the end of the answer is broken. Do you have an idea where i can find some more info about this? Aug 25, 2013 at 13:28
3

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

4
  • Like Aaron correctly stated, the web.config (or derivals from it .debug.config or .release.config) are 'static' in Azure. So I want to know if these mechanism also applies for the serviceconfiguration.cscfg...... Jul 13, 2011 at 11:41
  • I'm not sure, but this might be what you're looking for: blog.alexlambert.com/2010/05/… Jul 13, 2011 at 12:22
  • This is a similar solution with a bit more detail: blogs.msdn.com/b/tomholl/archive/2011/02/23/… Jul 13, 2011 at 12:24
  • 2
    As of April 2012, the "Publish to Windows Azure..." option correctly transforms the web.config file using the web.XXXX.config files.
    – jamie
    Apr 19, 2012 at 3:02
2

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

0

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.

1
  • This is correct, but you'd still need to develop something which looks at the cloud configs rather than the web.config as Aaron pointed out. Jan 19, 2011 at 20:10
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.