What is the recommended approach for deploying to multiple Azure environments (dev, test, production)?

筅森魡賤 提交于 2019-12-04 17:18:33

Assumption: you are using Web-Services, not Web-Sites. There is a difference.

There are 2 ways to get what you need:

  1. For worker role you can do app.config transformations almost in the same way you do in web.config. Only you'll need to do it with SlowCheetah. There is a nuget package for that, also there is VS extension to create transform files. There is too much faffing-about with this method. I never liked it, so move on to second option.

  2. If you run Web-Services, you can specify connection strings as part of worker-role configuration. Go to your Azure project and open properties of your worker-role:

There you can add database connection string. And create a configuration for every environment you run (dev, test, prod). And place a different connection string for every environment.

To get your connection string you execute:

CloudConfigurationManager.GetSetting("DatabaseConnectionString")

Once your site is deployed you'll see these configuration values in Configure tab in Azure Portal.

You should make the distinction between 'building in release mode' and 'deploying to environment X'.

Building in Release mode should just transform your configuration files to be 'production-ready'. With MsDeploy you can parameterize your configuration files so upon deployment they will be filled with the parameters as supplied by you to your MsDeploy script.

There is no magic bullet which will automatically change your connectionstrings etc per environment. But this way you can standardize your process which will greatly help with the stability of your product.

One thing to note is that the parameterization of your deployments will break the easy workflow 'publish' from within visual studio due to the fact that you are not given an option to fill in your parameters during the publish wizard... :'(

You should manage the connection strings through the azure portal rather than through config file transformations. With the MVC app this will be easy, go to the configure tab and set your connection strings there

For items like web jobs use Microsoft.WindowsAzure.ConfigurationManager which

provides a unified API to load configuration settings regardless of where the application is hosted - whether on-premises or in a Cloud Service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!