zoukankan      html  css  js  c++  java
  • Using XDT with Worker Role App.configs

     http://blog.abstractlabs.net/2011_02_01_archive.html

    Recently I wrote a worker role in windows azure and was hoping the app.config would transform much like the web.config in the web roles. Sadly this is not the case. The configuration transforms are very useful when making a distinction between production, staging and development environments. After a little research, I did discover how to roll my own hopefully Microsoft will extend this feature to the rest of the azure project types.

    Like the web roles this transform is only executed when a deploy is executed, here is how it was done:

    1. Un-load the project containing your worker role and app.config
    2. Edit the project file at the bottom add the following lines:
      1
      2
      3
      4
      5
      6
      7
      <usingtask taskname="TransformXml" assemblyfile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll">
      <target name="AfterCompile" condition="exists('app.$(Configuration).config')">
      <transformxml source="app.config" destination="$(IntermediateOutputPath)$(TargetFileName).config" transform="app.$(Configuration).config">
      </transformxml></target>
      </usingtask>


    3. Add the following Item Group:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      <ItemGroup>
      <Content Include="App.config" />
      <Content Include="App.Debug.Config">
       <DependentUpon>App.Config</DependentUpon>
       <SubType>Designer</SubType>
      </Content>
      <Content Include="App.Release.Config">
       <DependentUpon>App.Config</DependentUpon>
      </Content>
      </ItemGroup>
    4. Now add the new configuration files to the project App.Debug.config, App.Release.config
    5. Reload the worker role project project
    6. Unload the cloud service project that references the worker role
    7. Open the file for edit and add the following line:
      1
      2
      3
      4
      5
      <Target Name="CopyWorkerRoleConfigurations" BeforeTargets="AfterPackageComputeService">
       <Copy SourceFiles="..\{<b>PROJECT PATH</b>}\obj\$(Configuration)\{<b>ASSEMBLY NAME</b>}.dll.config" DestinationFolder="$(IntermediateOutputPath)\{<b>PROJECT NAME</b>}" OverwriteReadOnlyFiles="true"/>
      </Target>

    8. Reload the project file

    You will need to use the name of your project and the assembly name in the locations above. The paths are relative to the azure service project file. If you get lost you can add an element to the target and set the text to your path.
  • 相关阅读:
    JavaScript AMD 模块加载器原理与实现
    nodejs之日志管理
    实时监测每秒上行下行流量,一款 iOS Today Widget 监测器Demo,还可以可以监测内存大小、存储空间等信息
    Swift 2.0基本语法
    【京东助手】滑稽东试用助手 V1.6.0
    我也秀秀windows phone版博客园客户端
    asp.net做的网站账号登陆后注销不管用了
    分享个自己做的CSDN刷下载积分软件
    推荐一个很好用的HTTP操作类
    新软件马上就要完成了,先发篇文章YY下
  • 原文地址:https://www.cnblogs.com/RobotTech/p/2383835.html
Copyright © 2011-2022 走看看