MSBuild XmlMassUpdate Task

邮差的信 提交于 2019-12-19 19:53:38

问题


I wanted to ask a quick question regarding the behaviour of the MSBuild task XmlMassUpdate.

Has anyone found that the task will only copy unique nodes over to the content XML? For example, if I have a client node which has multiple children called endpoint, then it will only mass copy the first endpoint node while eliminating all the others.

I've provided some examples below of what I'm describing, many thanks in advance.

MSBuild Task:

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

Content:

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

Replacement:

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

Output:

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

回答1:


The XmlMassUpdate help section included in the MSBuildCommunityTasks help file shows examples of dealing with multiple elements that have the same name.

You need to differentiate the elements using a unique attribute, this attribute will be defined as an XmlMassUpdate "key". In your case, the name attribute will work. I believe this updated Replacement code below will fix your issue, notice the xmu attributes.

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


来源:https://stackoverflow.com/questions/1444366/msbuild-xmlmassupdate-task

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