如何将配置转换应用于 EntLib.config?
我有一个大型 Silverlight 项目,其中有一个笨重的 web.config,它使用了对 web.debug.config、web.uat.config 和 web.release.config 文件的转换。
我没有将我的 EntLib 配置与匹配的 EntLib.debug.config、EntLib.uat.config 和 EntLib.release.config 文件分离到 EntLib.config 中。我编辑了 .csproj 文件并使用 DependentUpon,以便这些文件嵌套在 EntLib.config 下。现在,当我使用“发布...”菜单选项将文件直接发布到测试服务器时,我尝试让 VS2010 应用转换。
我一直在尝试应用 this 如下所示,但它似乎不起作用。我可以在 obj\$(Configuration)\TransformWebConfig\transformed 中看到转换后的 EntLib.config 文件,但它尚未部署。我也尝试过使用 Project >构建部署包,然后我在另一台机器上运行它。两者都给我留下了原始形式的 EntLib.config 以及旁边的每个 EntLib.($Configuration).config 文件。应该有效吗?任何人可以提供的任何帮助将不胜感激。
<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);
 Configuration=$(Configuration); 
 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>
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.
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.
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);
Configuration=$(Configuration);
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 T4 和 T4 。 microsoft.com/en-us/library/bb126245.aspx" rel="nofollow">TextTransform.exe 根据构建配置创建不同的配置。您可以查看我的 app.config 片段,但相同的技术也适用于 web.config。
1) 项目结构
2) project.csproj 修改允许为指定平台/配置拥有最新的配置。
3) Configuration.tt 示例
4) Debug.App.tt 示例
I use T4 and TextTransform.exe to create different configs based on build configuration. You can take a look on my snippets for app.config, but the same technique can be applied for web.config.
1) Project structure
2) project.csproj modification allows to have up-to-date config for specified Platform/Configuration.
3) Configuration.tt sample
4) Debug.App.tt sample
我使用这篇文章解决了这个问题: 针对项目中任何 XML 文件的 Xml 文档转换 (XDT),作者:Vishal Joshi,并在此处发布了详细信息:如何将转换应用于 EntLib.config。
我自己的解决方案遵循 Vishal 的选择,将其 XDT 目标文件存储在项目中,以便将其存储在源代码管理中并可供每个人使用,而不是将其存储在本地计算机上。
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.
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.