Azure的辅助角色配置文件转换 [英] Azure Worker Role Config File Transformations

查看:197
本文介绍了Azure的辅助角色配置文件转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置一个新的工作角色,设置了几个新的配置的通过SlowCheetah改造它。当我建立了项目与选择的新的configs之一,我其实做看到CONFIGS文件夹得到你所期望的\\ bin文件夹下创建(为前。\\ BIN \\生产)。

I've setup a new worker role and setup a couple of new config transforms for it via SlowCheetah. When I build the project with one of the new configs selected, I do in fact see that configs folder get created underneath the \bin folder as you would expect (for ex. \bin\Production).

当我打包使用新的configs之一,我的web项目得到他们的CONFIGS适当变化,但我的辅助角色(这仅仅是一个库)部署一个云服务并不即使我看到\\ bin文件夹的更新下\\ BIN \\生产。

When I package a cloud service for deployment using one of the new configs, my web projects get their configs transformed appropriately but my worker role (which is just a library) does not even though I see underneath the \bin folder an updated \bin\production.

这将出现在湛蓝的包装工具被忽视了辅助角色库的配置设置。我怎样才能得到它从适当配置挑配置文件?

It would appear the azure packaging tooling is ignoring the config set for the worker role library. How can I get it to pick the config file from the appropriate the configuration?

推荐答案

是的,你可以做到这一点 - 一旦你知道如何它甚至很容易的结果
App.config中是没有改变的设计的幸好Azure团队所取得的构建/部署过程正是这些种情景很强的可扩展。你需要做的是相当有据可查的,但在一个非常迂回的方式和大多数文章假设你已经熟悉的MSBuild脚本等等。

Yes, you can do this - and it is even very easy once you know how.
App.config is not transformed by design but fortunately the Azure Team made the build/deploy process very extensible exactly for these kinds of scenarios. What you need to do is reasonably well documented, though in a very roundabout way and most articles assume you are already familiar with MSBuild scripts and the like.

下面,你会发现,你需要把你的项目,该项目将使这只是工作的行。这应该不会超过五分钟。请注意,这不是一个黑客 - 整个Azure的部署过程被设计为支持这种事情。

Below you will find the lines you need to put into your project that will make this Just Work. That should take no more than five minutes. Please note that this is not a hack - the whole Azure deploy process is designed to support this kind of thing.

如果您想了解更多,也有在底部的一些相关文章的链接。

If you want to know more, there are some links to related articles at the bottom.


  1. 建议的方式来实现这种天青的事情是的的使用的Web.config和App.config中,而是使用CloudConfigurationManager和使用角色设置。然而,有时,仅仅是不正确的答案,通常是因为需要的* .config设置(SMTP,WCF,ELMAH等)内置或第三方组件。

  2. Web配置转换是专为改变只在web.config。这意味着的app.config没有被设计改造的

  3. Web配置转换器仅设计为踢时的发布的,所以当你在本地运行,即使在云模拟器,你的web.config不会被改变。

  1. The recommended way to achieve this kind of thing in Azure is to not use Web.config and App.config but instead use the CloudConfigurationManager and use Role Settings. However, sometimes that just isn't the right answer, usually because of built-in or 3rd party components that require *.config settings (smtp, wcf, elmah etc).
  2. Web Config transformations is designed for transforming only the web.config. This means that app.config is not transformed by design.
  3. Web Config transformations is designed to only kick in when publishing so when you run locally, even in the Cloud Emulator, your Web.config won't be transformed.

就可以解决这个问题的方法是通过挂钩到了云计算项目的构建过程。当您将项目部署到Azure中,云项目将使用一个构建过程中,你可以挂接到建成。总之,云计算项目构建Web和工人角色和你的云项目中把它们与obj文件夹下。然后,它运行的进程,基本上所有的拉链,最多最后把结果到bin文件夹。从那里,ZIP文件和配置文件上传到Azure上。

The way we can solve this is by hooking into the build process for the Cloud project. When you deploy the project to Azure, the Cloud project will be built using a build process you can hook into. In short, the cloud project builds the web and worker roles and puts them under the Obj folder under your cloud project. It then runs a process that essentially zips all that up and finally put the result into the Bin folder. From there, the "zip" file and a configuration file is uploaded to Azure.

是手动编辑您的Cloud.csproj文件(如果你在Visual Studio中做到这一点,你需要首先卸载项目)。
再加入上述这一权利的结束< /项目> 标签:

Is to manually edit your Cloud.csproj file (if you do it from within Visual Studio you need to unload the project first). Then add this right above the closing </project> tag:

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets" />
    <PropertyGroup>
      <WorkerRoleDir>$(IntermediateOutputPath)WorkerRole1\</WorkerRoleDir>
      <AppConfigOriginal>$(WorkerRoleDir)WorkerRole1.dll.config</AppConfigOriginal>
      <AppConfigTransformer>$(SolutionDir)WorkerRole1\App.$(Configuration).config</AppConfigTransformer>
      <AppConfigAfterTransformed>$(WorkerRoleDir)AfterTransformed.config</AppConfigAfterTransformed>
    </PropertyGroup>
    <Target Name="TransformAppConfig" AfterTargets="AfterPackageComputeService">
      <Message Text="Transforming $(AppConfigOriginal) via $(AppConfigTransformer) to $(AppConfigAfterTransformed)" />
      <TransformXml Source="$(AppConfigOriginal)" Transform="$(AppConfigTransformer)" Destination="$(AppConfigAfterTransformed)" />
      <Copy SourceFiles="$(AppConfigOriginal)" DestinationFiles="$(WorkerRoleDir)App.Config.Original" />
      <Copy SourceFiles="$(AppConfigAfterTransformed)" DestinationFiles="$(AppConfigOriginal)" />
    </Target>

注释


  • 有一对夫妇中就有硬codeD的路径,你将不得不进行修改。我相信有一种方法可以让他们软,但需要更多的MSBuild技巧比我有。

  • 的转变,实际上运行当你部署到云计算的本地模拟器,但它不会被使用的 的。这样,结果是其也未转化的Web.config的行为一致。但是,如果你的转变是失败,你会得到一个生成错误,即使只是在模拟器中运行。

  • 参见这等SO质疑

  • An深入探索

  • Tom荷兰人高度链接文章直接的MSBuild
  • 部署

    Notes

    • There are a couple of hard-coded paths in there that you will have to modify. I am sure there is a way to make them soft but that requires more MSBuild skills than I have.
    • The transformation will actually run when you deploy to your local Cloud Emulator, but it won't be used. As such, the result is consistent with the behavior of Web.config which is also not transformed. But, if your transformation was to fail, you will get a build error even when just running in the Emulator.
    • See also This other SO question
    • An in-depth exploration
    • Tom Hollanders highly linked article on deploying directly from MSBuild
    • 这篇关于Azure的辅助角色配置文件转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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