2015-06-25 21 views
0

我们的.net构建系统使用Enterprise Library 4.1通过调用MergeConfiguration.exe来替换默认web.config设置,并为每个环境提供原始web.config和增量文件(如测试和生产),以便生成的安装程序打包所有环境的特定web.config并根据环境安装正确的版本。如何为不同环境合并.net自定义配置部分

这适用于企业库已知的部分,例如appSettings部分。但是,我们还有一些自定义部分,我想区分不同的环境,如下所示。

测试

<RoutingSection type="AbcSystem.RoutingSection, AbcSystem"> <Route Source="1" Destination="2" /> ... </RoutingSection>

另外,制造

<RoutingSection type="AbcSystem.RoutingSection, AbcSystem"> <Route Source="1" Destination="3" /> ... </RoutingSection>

理想整个自定义栏目在增量文件规定,建设过程中,取代了原来的网页的默认版本。配置。

没有实现我们自己的增量合并工具,我还没有找到解决方案。相信这是软件开发的共同需求,我正在寻求一种解决方案,理想情况下不需要对上述过程进行太多更改。它不一定是企业库。提前致谢。

+0

这都是Xml。使用xml-update msbuild任务。 – granadaCoder

回答

0

我最终使用了SlowCheetah,为每个环境生成一个转换后的配置文件。这也是TFS构建友好的,不需要修改构建过程。我还将先前使用Enterprise Library 4.1进行的合并移动到SlowCheetah,并将其与自定义部分一起移动。

+0

好的...这是“事后”设置的好选择。我从一开始就设置了xml-transforms,所以它没有那么痛苦.....当一个新的设置出现时。 – granadaCoder

0

的MSBuild的下方将复制原始文件和更新2的值3

您必须安装MSBuildCommunityTasks并获得了“引进项目”文件名右....但低于逻辑将为你工作。

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped"> 

    <!-- 
    <UsingTask AssemblyFile="$(ProgramFiles)\MSBuild\MSBuild.Community.Tasks.dll" TaskName="Version"/> 
    --> 
    <Import Project="$(MSBuildExtensionsPath32)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" /> 



    <PropertyGroup> 
     <!-- Always declare some kind of "base directory" and then work off of that in the majority of cases --> 
     <WorkingCheckout>.</WorkingCheckout> 
    </PropertyGroup> 

    <PropertyGroup> 
     <DestinationForProductionValue>3</DestinationForProductionValue> 
    </PropertyGroup> 

    <Target Name="AllTargetsWrapped"> 
     <CallTarget Targets="CopyItTarget" /> 
     <CallTarget Targets="WriteXmlPeekValue" /> 
    </Target> 


    <Target Name="CopyItTarget"> 
     <Copy SourceFiles="$(WorkingCheckout)\Parameters.xml" DestinationFiles="$(WorkingCheckout)\Parameters_PRODUCTION.xml"/>  
     <Error Condition="!Exists('$(WorkingCheckout)\Parameters_PRODUCTION.xml')" Text="No Copy Is Bad And Sad" /> 
    </Target> 


    <Target Name="WriteXmlPeekValue" Condition=" '$(DestinationForProductionValue)' != '' "> 
     <XmlPoke 
    XmlInputPath="$(WorkingCheckout)\Parameters_PRODUCTION.xml" 
      Query="/root/RoutingSection/Route/@Destination" 
    Value="$(DestinationForProductionValue)" /> 
    </Target> 




</Project> 
+0

感谢您的建议,granadaCoder。不幸的是,我们有太多的值,有时需要更新整个自定义部分。最后我用SlowCheetah。 – Xeon