XmlMassUpdate - 替换值节点

发布于 2024-08-01 17:51:33 字数 1380 浏览 1 评论 0原文

我正在尝试使用 XmlMassUpdate 根据构建版本类型更新我的配置文件。 似乎没有关于如何在任何地方更新新的 app.config (vs2008) 设置格式的文档。

这是配置部分:

<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>

我正在尝试更新此文件中的 URL 值:

<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>

运行脚本,我可以替换“name”或“serializeAs”属性,但不能替换值节点。

我将如何更换值节点?

问候

特里斯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑着哭最痛 2024-08-08 17:51:33

以下脚本对我来说工作正常(在 1.3.0.471 上运行,这可能是每晚构建):

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 (由构建生成)

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文