Windows Azure 连接字符串 - 如何处理本地与生产?
我正在部署一些 Windows Azure 项目,我注意到不断地将我的角色配置设置从使用 LocalStorage 切换到实际使用我的 Windows Azure 存储连接字符串有点痛苦。
对于本地开发,我想使用这个:
UseDevelopmentStorage=true
但是对于已部署的应用程序,我想使用类似的东西:
DefaultEndpointsProtocol=https;AccountName=myAccountName;AccountKey=blah
我最终要么在部署之前更改我的角色的配置连接字符串,要么如果我忘记这样做,我会尝试进入 Windows Azure 门户并更改它们(但这通常发生在我一遍又一遍地观察我的角色实例启动和停止之后)。
我觉得我错过了一些基本的东西,但是有没有一种直接的方法可以让部署过程将我的角色连接设置切换为使用生产存储帐户而不是本地存储?
I'm in the process of deploying some windows azure projects and I've noticed that it's a bit of a pain to constantly switch my role configuration settings from using LocalStorage to actually use my Windows Azure Storage connection strings.
For local development, I want to use this:
UseDevelopmentStorage=true
But for deployed apps, I want to use something like:
DefaultEndpointsProtocol=https;AccountName=myAccountName;AccountKey=blah
I end up either changing my role's configuration connection strings just before I deploy, or if I forget to do that, I'll attempt to go into the Windows Azure portal and change them (but that usually happens after I watch my role instances start and stop over and over).
I feel like I'm missing something basic, but is there a straight-forward way to have the deployment process switch my role connection settings to use the production storage accounts instead of local storage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以在 Azure SDK 1.7 中使用 CloudConfigurationManager http://msdn.microsoft.com /en-us/LIBRARY/microsoft.windowsazure.cloudconfigurationmanager
首先在 ServiceConfiguration.cscfg(例如 ServiceConfiguration.Cloud.cscfg)中查找配置设置。如果不存在,则会回退到 web.config 和 app.config
例如,
将在相应的 cscfg 文件中查找 StorageConnectionString 设置,然后它将搜索 web.config,然后搜索 app.config。
You can use CloudConfigurationManager in Azure SDK 1.7 http://msdn.microsoft.com/en-us/LIBRARY/microsoft.windowsazure.cloudconfigurationmanager
This starts by looking in the ServiceConfiguration.cscfg e.g. ServiceConfiguration.Cloud.cscfg for config setting. If it isn't there it falls back to web.config and app.config
For example
Will look in the appropriate cscfg file for StorageConnectionString setting, then it will search the web.config and then app.config.
如果您想使用 Visual Studio 配置转换,请参阅我的回答帕纳吉奥蒂斯提到的问题。
If you want to use Visual Studio config transformations, see my answer to the question Panagiotis mentioned.
从一个连接字符串切换从开发转向云时的另一个问题
干杯。
Switching from one connectionstring to another when moving from development to cloud
Cheers.
如果您使用 CI 服务器,您可以自动更改连接字符串。详细信息此处。
If you use CI server you can change the connection string there automatically. Details here.
我在这里回答了类似的问题:
Visual Studio 2010 可以将调试或发布转换应用于 Web.config,但是 Azure 设置呢?
I've answered a similar question here:
Visual Studio 2010 can apply Debug or Release transformations to Web.config, but what about the Azure settings?