每个环境的 Azure web.config
我在 VS2010 中有一个 Azure 项目(Azure 1.3)。有 2 个 Web 角色、1 个网页项目和 1 个 WCF 项目。在调试模式下,我希望 Web 项目使用用于 DEV 环境的 web.config,并且在发布用于 PROD 的 web.config 时必须使用。
最好的方法是什么?
目前,我在使用带有转换 XSLT 的 Web.Debug.config 时遇到问题。好像在Azure上不行啊……
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....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
用不同的方式解决你的问题。想象一下,在使用 Azure 时,web.config 始终是静态的并且永远不会改变。改变的是你的ServiceConfiguration.cscfg。
我们所做的是创建我们自己的配置提供程序,它首先检查 ServiceConfiguration.cscfg,然后如果设置/连接字符串不存在,则返回到 web.config。这允许我们在开发期间直接在 IIS/WCF 中运行服务器,然后在部署到 Azure 时具有不同的设置。在某些情况下,您必须使用 web.config(是的,我在这里指的是 WCF),在这些情况下,您必须编写代码并创建约定,而不是将所有内容都存储在 web.config 中。我有一篇博客文章,其中展示了我在处理 WIF (Windows Identity Foundation) 和 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.
我同意摩西的观点,很好的问题!
Visual Studio 2010 包含针对此类问题的解决方案:web.config 转换。如果您查看您的 Web 角色,您会发现它包括 Web.Debug.config 和 Web.Release.config 以及传统的 web.config。这些文件用于在部署期间转换 web.config。
典型的示例是“我需要不同的数据库连接字符串进行开发和发布”,但它也适合您的情况。
Visual Web 开发团队有一篇出色的博客文章,解释了如何使用此功能(不用费心阅读 MSDN 文档,我知道它是如何工作的,但仍然不理解文档) 。查看 http:// /blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx
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
我喜欢这个问题!
对于辅助角色,我通过在运行时检测环境并使用自定义配置在新的 AppDomain 中启动我的“应用程序”来解决这个问题:
这是令人难以置信的高效!
我想对Web项目做同样的事情,因为使用Azure特定配置很麻烦:
我仍在寻找正确的方法来做到这一点,就像这篇文章
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 :
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 :
I'm still searching the right way to do that, like in this post
另一种可能的解决方案是拥有两个 CloudService 项目,每个项目都有特定的 ServiceConfiguration.cscfg(dev/prod)。使用 Dev 进行开发,但部署 Prod。
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.
这取决于您是想让它在本地计算机上还是在持续集成中工作。
It depends on whether you want to make it work on your local machine or inside continuous integration.