XmlMassUpdate - Replace Value Node

强颜欢笑 提交于 2020-01-03 15:34:44

问题


I'm trying to use XmlMassUpdate to update my config files based on build Version type. There seems to be no documentation on how to update the new app.config (vs2008) settings formats anywhere.

This is the config section:

<applicationSettings>
<CTC.Mica.ClientService.Properties.Settings>
  <setting name="PipeName" serializeAs="String">
    <value>\\.\pipe\micaPipe</value>
  </setting>
  <setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService"
      serializeAs="String">
    <value>URL</value>
  </setting>
</CTC.Mica.ClientService.Properties.Settings>
</applicationSettings>

And i am trying to update the URL value from this file:

<Debug>
    <setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
      <value>DEVURL</value>
    </setting>
</Debug>

<Test>
    <setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
      <value>TESTURL</value>
    </setting>
</Test>

<Release>
    <setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
      <value>LIVEURL</value>
    </setting>
</Release>

Running the script, i can replace either the "name" or the "serializeAs" attributes, but not the value node.

How would i go about replacing the value node?

Regards

Tris


回答1:


The following scripts work fine for me (running on 1.3.0.471 which might be a nightly build):

build.proj

<Project DefaultTargets="Run" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.targets" />
    <Target Name="Run">
        <Delete Condition="Exists('output.xml')" Files="output.xml"/>
        <XmlMassUpdate 
            ContentFile="input.xml"
            ContentRoot="/test"
            SubstitutionsFile="subs.xml"
            SubstitutionsRoot="/substitutions/release"
            MergedFile="output.xml"
            />
    </Target>
</Project>

input.xml

<test>
  <setting name="PipeName" serializeAs="String">
    <value>\\.\pipe\micaPipe</value>
  </setting>
  <setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
    <value>URL</value>
  </setting>
</test>

subs.xml

<substitutions xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">
    <release>
        <setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="Testing">
            <value>LIVEURL</value>
        </setting>
    </release>
</substitutions>

output.xml (generated by build)

<test>
  <setting name="PipeName" serializeAs="String">
    <value>\\.\pipe\micaPipe</value>
  </setting>
  <setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="Testing">
    <value>LIVEURL</value>
  </setting>
</test>


来源:https://stackoverflow.com/questions/1294438/xmlmassupdate-replace-value-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!