をPowerShellのか、MSBuildのを使用して、または他のメカニズムによって、それを達成するためには使用してこれを行う方法の例でどのようにこの
<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>
のようなグループXCopyのItemgroupしたいと思いますGroup-Object
コマンドレットxcopy要素をグループ化してDestination
とし、Include
のパスをセミコロンで区切った文字列に結合します。出力は新しいXMLドキュメントに格納され、ディスクに保存されます。これは、元のプログラムでは更新されません。新しい統合XMLを元のXMLに貼り付けるだけでコピーできます。
更新ファイル全体が表示されているので、XPathに問題を引き起こすデフォルトの名前空間があります。この問題を回避するには2つの方法があります。
- 使用namespace agnostic xpath
- ここ
名前空間マネージャを使って名前空間に依存しないXPathを使用して更新例です。インデントを取得するには、XMLオブジェクト処理の後にテキストファイルの処理を行う必要があります。
$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
出力を作成します。
<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>
次の問題のバディになっています。値 "E:\ Powershellscripts \ Comp1.Targets"を "System.Xml.XmlDocument"に変換することはできません。エラー:「ルートレベルのデータが無効です。行1、位置1」 – Samselvaprabu
入力ファイルは以下のようになります。 "<?xml version =" 1.0 "encoding =" utf-8 "?>< ComponentNotifications Include = "[email protected]" /> ".. \ .. \ .. \ Mycomponent \ depl \ BOM \ Folder1 Destination> ".. \ .. \ .. \ Mycomponent \ depl \ BOM \ Folder1 Destination> –
Samselvaprabu
私は理解のために私の質問を編集しました – Samselvaprabu