views:

430

answers:

1

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"&gt;
    <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>
+3  A: 

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