如何将配置变换应用于EntLib.config? [英] How can I apply configuration transforms to EntLib.config?

查看:547
本文介绍了如何将配置变换应用于EntLib.config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型的Silverlight项目,带有一个笨重的web.config,它使用了对web.debug.config,web.uat.config和web.release.config文件的转换。

I had a large Silverlight project with an unwieldy web.config, which used transforms against the web.debug.config, web.uat.config, and web.release.config files.

我没有分离出我的EntLib配置到EntLib.config,匹配EntLib.debug.config,EntLib.uat.config和EntLib.release.config文件。我编辑了.csproj文件并使用Dependent Upon,以便文件嵌套在EntLib.config下。现在我试图让VS2010应用变换,当我使用Publish ...菜单选项发布文件直接到测试服务器。

I've not separated out my EntLib configuration into EntLib.config, with matching EntLib.debug.config, EntLib.uat.config and EntLib.release.config files. I've edited the .csproj file and used DependentUpon so that the files are nested under EntLib.config. Now I'm trying to get VS2010 to apply the transforms when I use the Publish... menu option to publish the files straight to the test server.

尝试应用,如下所示,但它似乎不工作。我可以看到转换的EntLib.config文件在obj \ $(配置)\TransformWebConfig\transformed,但它没有部署。我也试过使用Project> Build Deployment Package,然后我在另一台机器上运行它。两者留给我EntLib.config的原始形式加上每个EntLib。($配置).config文件旁边。应该工作吗?任何人都可以提供的任何帮助都会感激。

I've been trying to apply this as shown below but it doesn't seem to work. I can see the transformed EntLib.config file in obj\$(Configuration)\TransformWebConfig\transformed but it isn't deployed. I've also tried using Project > Build Deployment Package which I've then run on another machine. Both leave me with EntLib.config in its original form plus each of the EntLib.($Configuration).config files alongside it. Should it work? Any help anyone can offer would be appreciated.

<PropertyGroup>
    <ConfigFileName>EntLib.config</ConfigFileName>
  </PropertyGroup>
  <PropertyGroup>
    <!-- This property is used to handle circular dependency between
    TransformWebConfig and our custom target TransformAppConfig   -->
    <FirstRun Condition="$(FirstRun) == ''">true</FirstRun>
  </PropertyGroup>
  <!-- This target will be called one time after a call to TransformWebConfig -->
  <Target Name="TransformAppConfig" AfterTargets="TransformWebConfig" Condition="$(FirstRun) == 'true'">
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="TransformWebConfig" Properties="ProjectConfigFileName=$(ConfigFileName);&#xD;&#xA;                         Configuration=$(Configuration);                        &#xD;&#xA;                         FirstRun=false" />
  </Target>
  <!-- This target will be called one time before PreAutoParameterizationWebConfigConnectionStrings
       to add $(ConfigFileName) to autoparameterization step -->
  <Target Name="AddToAutoParameterizationStep" BeforeTargets="PreAutoParameterizationWebConfigConnectionStrings">
    <ItemGroup>
      <_WebConfigsToAutoParmeterizeCS Include="@(FilesForPackagingFromProject)" Condition="('%(FilesForPackagingFromProject.Filename)%(FilesForPackagingFromProject.Extension)'=='$(ConfigFileName)') And !%(FilesForPackagingFromProject.Exclude)">
        <TransformOriginalFile>$(AutoParameterizationWebConfigConnectionStringsLocation)\original\%(DestinationRelativePath)</TransformOriginalFile>
        <TransformOutputFile>$(AutoParameterizationWebConfigConnectionStringsLocation)\transformed\%(DestinationRelativePath)</TransformOutputFile>
        <TransformScope>$(_PackageTempDir)\%(DestinationRelativePath)</TransformScope>
      </_WebConfigsToAutoParmeterizeCS>
      <_WebConfigsToAutoParmeterizeCSOuputFiles Include="@(_WebConfigsToAutoParmeterizeCS->'%(TransformOutputFile)')">
      </_WebConfigsToAutoParmeterizeCSOuputFiles>
    </ItemGroup>
  </Target>


推荐答案

我使用这篇文章解决了这个问题:任何XML文件的Xml文档转换(XDT)你的项目,并在这里公布的细节:如何将变换应用到EntLib.config

I solved this using this article: Xml Document Transforms (XDT) for any XML file in your project by Vishal Joshi and posted the specifics here: How to apply transforms to EntLib.config.

我自己的解决方案遵循Vishal的选项将XDT目标文件存储在项目中,源控件,并且对每个人都可用,而不是将其存储在本机上。

My own solution followed Vishal's option to store his XDT targets file in the project so that it gets stored in source control and is available to everyone, rather than storing it locally on the machine.

这篇关于如何将配置变换应用于EntLib.config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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