Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7078473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:33:07+00:00 2026-05-28T06:33:07+00:00

I am having Msbuild XML file like this. <?xml version=1.0 encoding=utf-8?> <Project xmlns=schemas.microsoft.com/developer/msbuild/2003> <ItemGroup>

  • 0

I am having Msbuild XML file like this.

<?xml version="1.0" encoding="utf-8"?> 
  <Project xmlns="schemas.microsoft.com/developer/msbuild/2003">
         <ItemGroup>
             <Notifications Include="someone@gmail.com"/>
         </ItemGroup>
    <ItemGroup> 
         <Xcopy Include="..\..\..\Release\UtilitiesAssembly.dll"> 
             <Destination>"..\..\..\Mycomponent\depl\BOM\Folder1</Destination> 
         </Xcopy>
         <Xcopy Include="..\..\..\Release\Core.assembly.dll">
             <Destination>"..\..\..\Mycomponent\depl\BOM\Folder1</Destination>
         </Xcopy>
         <Xcopy Include="..\..\..\Release\UIAssembly.dll"> 
             <Destination>"..\..\..\Anothercomponent\Folder1</Destination> 
         </Xcopy>
         <Xcopy Include="..\..\..\Release\Core.assembly.dll">
             <Destination>"..\..\..\Anothercomponent\depl\BOM</Destination>
         </Xcopy>
    </Itemgroup>
  </Project>

Actually i would like to group XCopy Itemgroup like this

      <Xcopy Include="..\..\..\Release\UtilitiesAssembly.dll;
                    ..\..\..\Release\\Core.assembly.dll;">
      <Destination>"..\..\..\Mycomponent\depl\BOM\Folder1</Destination>
     </Xcopy>

     <Xcopy Include="..\..\..\Release\UIAssembly.dll;">
      <Destination>"..\..\..\Anothercomponent\Folder1</Destination>
     </Xcopy>

     <Xcopy Include="..\..\..\Release\Core.assembly.dll">
             <Destination>"..\..\..\Anothercomponent\depl\BOM</Destination>
     </Xcopy>

How to achieve it using Powershell or Msbuild or by some other mechanism

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:33:08+00:00Added an answer on May 28, 2026 at 6:33 am

    Here is an example how to do this using the Group-Object cmdlet. It will group the xcopy elements by Destination and combine the Include paths into a semi-colon separated string. The output is stored in a new XML document and saved to disk. This doesn’t programatically update the original. You can just copy paste the new consolidated XML over you original XML.

    Update Now that I see your whole file, I see it has a default namespace which causes problems with XPath. There are two ways to get around this problem.

    1. Use namespace agnostic xpath
    2. Use a namespace manager

    Here is an updated example using namespace agnostic xpath. Also in order to get the indentation you are looking for we’ll need to do some text file processing after the XML object processing.

    $xml="Myinput.xml"
    $tempXmlFile = "C:\New.xml"
    
    $outXml = New-Object System.Xml.XmlDocument
    $outXml.AppendChild($outXml.CreateElement("root")) > $null
    
    $x = [xml] (Get-Content $xml)
    $x.SelectNodes("//*[local-name()='Xcopy']") | Group-Object Destination | % {
        $includePaths = ($_.Group | Select-Object -ExpandProperty Include) -join ";"
        $element = $outXml.CreateElement("Xcopy")
        $element2 = $outXml.CreateElement("Destination")
        $element2.InnerText = $_.Name
        $element.AppendChild($element2) > $null
        $element.SetAttribute("Include", $includePaths)
        $outXml.DocumentElement.AppendChild($element) > $null
    }
    $outXml.Save($tempXmlFile)
    
    $data = Get-Content $tempXmlFile | % {
        $search = 'Include="'
        $index = $_.IndexOf('Include="')
        if ($index -gt 0) { 
            $spaces = ( ' ' * ($index + $search.length) ) 
        }
        $_ -replace ';', ";`n${spaces}"
    }
    $data | Set-Content $tempXmlFile
    & notepad $tempXmlFile
    

    Creates output:

    <root>
      <Xcopy Include="..\..\..\Release\UtilitiesAssembly.dll
                      ..\..\..\Release\Core.assembly.dll">
        <Destination>"..\..\..\Mycomponent\depl\BOM\Folder1</Destination>
      </Xcopy>
      <Xcopy Include="..\..\..\Release\UIAssembly.dll">
        <Destination>"..\..\..\Anothercomponent\Folder1</Destination>
      </Xcopy>
      <Xcopy Include="..\..\..\Release\Core.assembly.dll">
        <Destination>"..\..\..\Anothercomponent\depl\BOM</Destination>
      </Xcopy>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue with the Attrib task from the MSBuild Community Tasks Project
I've got a WiX installer project which uses MSBuild to generate the MSI file.
Problem I'm having trouble using XdcMake to generate XML documentation in a C++ project
I'd like to create a TFS build project without having to learn how to
On my local dev machine this works perfectly: msbuild project.name.csproj /p:DeployOnBuild=true /p:DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir=c:\proyectos\folder1\deploy /p:AutoParameterizationWebConfigConnectionStrings=false
After having found the answer to my question about the 64-bit version of MSBuild
Is it possible in MSBuild to batch tasks without having the metadata value you
Having been a PHP developer on LAMP servers for quite a while, is there
Having a heckuva time with this one, though I feel I'm missing something obvious.
Having programmed through emacs and vi for years and years at this point, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.