什么是部署到多个蔚蓝的环境(开发,测试,生产)建议的方法? [英] What is the recommended approach for deploying to multiple azure environments(dev, test, production)?

查看:141
本文介绍了什么是部署到多个蔚蓝的环境(开发,测试,生产)建议的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用mvc5一个C#的Web应用程序。它当前运行在Azure上,我有一个开发,测试和生产实例。我需要做什么做保证,由于应用程序推送到每个环境的数据库连接字符串会自动改变?我知道这是可能的web.config文件,你可以定义Web.Debug.Config等,但我将如何去为这个在Azure上不同的辅助角色?我一直都在互联网上寻找一个解决方案。任何帮助将大大AP preciated。概括地说,我愿做用于多个web.config文件中但蔚蓝相同的方法。

I have an c# web application using mvc5. It currently runs on azure and I have a dev, test, and production instances. What do I need to do to ensure that the database connection strings will automatically change as the application is pushed to each environment? I know this is possible with web.config as you can define Web.Debug.Config, etc, but how would I go about this for different worker roles on azure? I have been all over the internet looking for a solution. Any help would be greatly appreciated. In a nutshell, I would like to do the same approach used for the multiple web.config files but for azure.

由于一些额外的背景下,我的解决方案,我有我repositorybase分解成一个单独的项目,并有我试图抓住从配置文件(在连接字符串假设domain.dll是包含它的库名)。作为第一本,但工​​作时,我只是使用的web.config当我跑我的域名从另一个辅助角色的dll文件的配置开始返回null;因为从不同的工作进程(非网络)上运行时,此code将无法运行。这似乎是介绍一个有趣的问题,如果我需要使用domain.dll code网之外,蔚蓝之外吗?我如何仍然认为,Azure和web.config中提供连接字符串好处?

As some additional background, for my solution I have my repositorybase broken out into a separate project and there I am trying to grab the connection string from the configuration files(let's say domain.dll is the name of the library that contains it). As first this worked when I was only using web.config but when I had to run my domain dll files from another worker role the configuration began to return null; because this code would not run when run from a different worker process(non web). This seems to introduce an interesting problem, what if I need to use the domain.dll code outside the web and outside of azure? How do I still maintain the connection string benefits that azure and web.config provide?

推荐答案

假设:您正在使用网络服务,而不是web站点。是有区别的。

有2种方式来获得你所需要的:

There are 2 ways to get what you need:


  1. 有关工作人员的角色,你可以做的app.config 转换几乎是在你 web.config中做同样的方式。只有你需要做它<一个href=\"http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx\"相对=nofollow> SlowCheetah 。有一个包的NuGet为,也有VS扩展来创建转换文件。有太多faffing - 大约用这种方法。我从来不喜欢它,所以移动到第二个选项。

  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.

如果您运行的网络服务,您可以指定连接字符串作为工人的角色配置的一部分。转到您的Azure项目和你的工人角色的开放性:

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")

在您的网站部署您会看到配置在Azure的门户选项卡这些配置值。

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

这篇关于什么是部署到多个蔚蓝的环境(开发,测试,生产)建议的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆