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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -3608,317 +4010,59 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1
index 59218e6a733..6630a28693c 100644
--- a/tools/packaging/packaging.psm1
+++ b/tools/packaging/packaging.psm1
@@ -3044,6 +3044,38 @@ function Test-FileWxs
}
}
+ # get all the file components from the files.wxs
+ $components = $filesAssetXml.GetElementsByTagName('Component')
+ $componentRefs = $filesAssetXml.GetElementsByTagName('ComponentRef')
+
+ $componentComparison = Compare-Object -ReferenceObject $components.id -DifferenceObject $componentRefs.id
+ if ( $componentComparison.Count -gt 0){
+ $passed = $false
+ Write-Verbose "Rebuilding componentRefs" -Verbose
+
+ # add all the file components to the patch
+ foreach($component in $components)
+ {
+ $componentId = $component.Id
+ Write-Verbose "Removing $componentId" -Verbose
+ Remove-ComponentRefNode -Id $componentId -XmlDoc $newFilesAssetXml -XmlNsManager $xmlns
+ }
+
+ # There is only one ComponentGroup.
+ # So we get all of them and select the first one.
+ $componentGroups = @($newFilesAssetXml.GetElementsByTagName('ComponentGroup'))
+ $componentGroup = $componentGroups[0]
+
+ # add all the file components to the patch
+ foreach($component in $components)
+ {
+ $id = $component.Id
+ Write-Verbose "Adding $id" -Verbose
+ $newComponentRef = New-XmlElement -XmlDoc $newFilesAssetXml -LocalName 'ComponentRef' -Node $componentGroup -PassThru -NamespaceUri 'http://schemas.microsoft.com/wix/2006/wi'
+ New-XmlAttribute -XmlDoc $newFilesAssetXml -Element $newComponentRef -Name 'Id' -Value $id
+ }
+ }
+
if (!$passed)
{
$newXmlFileName = Join-Path -Path $env:TEMP -ChildPath ([System.io.path]::GetRandomFileName() + '.wxs')