gpt4 book ai didi

MSBuild XmlMassUpdate 任务

转载 作者:行者123 更新时间:2023-12-02 12:11:18 24 4
gpt4 key购买 nike

我想问一个有关 MSBuild 任务 XmlMassUpdate 行为的简单问题。

有人发现该任务只会将唯一节点复制到内容 XML 中吗?例如,如果我有一个客户端节点,它有多个称为端点的子节点,那么它只会批量复制第一个端点节点,同时消除所有其他端点节点。

我在下面提供了一些我所描述的示例,非常感谢。

MSBuild 任务:

<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('web.config')" Files="web.config"/>
<XmlMassUpdate
ContentFile="app.config"
ContentRoot="configuration/system.servicemodel"
SubstitutionsFile="wcf.config"
SubstitutionsRoot="/system.servicemodel"
MergedFile="web.config"
/>
</Target>
</Project>

内容:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.servicemodel/>
</configuration>

替换:

<?xml version="1.0" encoding="utf-8" ?>
<system.servicemodel>
<client>
<endpoint binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_LargeMessage"
contract="ClaimsService.IClaimsService"
name="WSHttpBinding_IClaimsService">
</endpoint>
<endpoint binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_LargeMessage"
contract="LateCertificationAdminService.ILateCertificationAdminService"
name="WSHttpBinding_ILateCertificationAdminService">
</endpoint>
</client>
</system.servicemodel>

输出:

<?xml version="1.0" encoding="utf-8" ?>
<system.servicemodel>
<client>
<endpoint binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_LargeMessage"
contract="ClaimsService.IClaimsService"
name="WSHttpBinding_IClaimsService">
</endpoint>
</client>
</system.servicemodel>

最佳答案

MSBuildCommunityTasks 帮助文件中包含的 XmlMassUpdate 帮助部分显示了处理具有相同名称的多个元素的示例。

您需要使用唯一属性来区分元素,该属性将被定义为 XmlMassUpdate“键”。在您的情况下,名称属性将起作用。我相信下面更新的替换代码将解决您的问题,请注意 xmu 属性。

<?xml version="1.0" encoding="utf-8" ?>
<system.servicemodel>
<client xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">
<endpoint xmu:key="name"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_LargeMessage"
contract="ClaimsService.IClaimsService"
name="WSHttpBinding_IClaimsService">
</endpoint>
<endpoint xmu:key="name"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_LargeMessage"
contract="LateCertificationAdminService.ILateCertificationAdminService"
name="WSHttpBinding_ILateCertificationAdminService">
</endpoint>
</client>
</system.servicemodel>

关于MSBuild XmlMassUpdate 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1444366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com