diff --git a/assets/Product.wxs b/assets/Product.wxs index 2354fa8018..36e39a34e7 100644 --- a/assets/Product.wxs +++ b/assets/Product.wxs @@ -4,16 +4,17 @@ - - + + + - + @@ -22,7 +23,7 @@ - + @@ -31,15 +32,11 @@ - - - - - + - + @@ -60,7 +57,7 @@ - + @@ -106,7 +103,7 @@ - - + @@ -168,7 +165,7 @@ - + diff --git a/assets/files.wxs b/assets/files.wxs index 4eba4ad129..f99eb511c4 100644 --- a/assets/files.wxs +++ b/assets/files.wxs @@ -1,1921 +1,1917 @@ - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1923,1191 +1919,1194 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + + + + @@ -3341,7 +3340,6 @@ - @@ -4108,9 +4106,10 @@ - + + diff --git a/tools/ci.psm1 b/tools/ci.psm1 index 5e4ee9ec17..2329b56db9 100644 --- a/tools/ci.psm1 +++ b/tools/ci.psm1 @@ -468,7 +468,7 @@ function Invoke-CIFinish $artifacts = New-Object System.Collections.ArrayList foreach ($package in $packages) { - if (Test-Path $package) + if (Test-Path $package -ErrorAction Ignore) { Write-Log "Package found: $package" } diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index f230320c12..4473c7cca4 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -2996,21 +2996,6 @@ function New-MSIPackage Write-Verbose "Create MSI for Product $productSemanticVersionWithName" - [Environment]::SetEnvironmentVariable("ProductSourcePath", $staging, "Process") - # These variables are used by Product.wxs in assets directory - [Environment]::SetEnvironmentVariable("ProductName", $ProductName, "Process") - [Environment]::SetEnvironmentVariable("ProductVersion", $ProductVersion, "Process") - [Environment]::SetEnvironmentVariable("SimpleProductVersion", $simpleProductVersion, "Process") - [Environment]::SetEnvironmentVariable("ProductSemanticVersion", $ProductSemanticVersion, "Process") - [Environment]::SetEnvironmentVariable("ProductVersionWithName", $productVersionWithName, "Process") - if (!$isPreview) - { - [Environment]::SetEnvironmentVariable("IconPath", 'assets\Powershell_black.ico', "Process") - } - else - { - [Environment]::SetEnvironmentVariable("IconPath", 'assets\Powershell_av_colors.ico', "Process") - } $fileArchitecture = 'amd64' $ProductProgFilesDir = "ProgramFiles64Folder" if ($ProductTargetArchitecture -eq "x86") @@ -3018,17 +3003,11 @@ function New-MSIPackage $fileArchitecture = 'x86' $ProductProgFilesDir = "ProgramFilesFolder" } - [Environment]::SetEnvironmentVariable("ProductProgFilesDir", $ProductProgFilesDir, "Process") - [Environment]::SetEnvironmentVariable("FileArchitecture", $fileArchitecture, "Process") $wixFragmentPath = Join-Path $env:Temp "Fragment.wxs" - $wixObjProductPath = Join-Path $env:Temp "Product.wixobj" - $wixObjFragmentPath = Join-Path $env:Temp "files.wixobj" # cleanup any garbage on the system Remove-Item -ErrorAction SilentlyContinue $wixFragmentPath -Force - Remove-Item -ErrorAction SilentlyContinue $wixObjProductPath -Force - Remove-Item -ErrorAction SilentlyContinue $wixObjFragmentPath -Force $packageName = $productSemanticVersionWithName if ($ProductNameSuffix) { @@ -3043,10 +3022,24 @@ function New-MSIPackage } Write-Log "verifying no new files have been added or removed..." - Start-NativeExecution -VerboseOutputOnError { & $wixPaths.wixHeatExePath dir $staging -dr VersionFolder -cg ApplicationFiles -ag -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v} + $arguments = @{ + IsPreview = $isPreview + ProductSourcePath = $staging + ProductName = $ProductName + ProductVersion = $ProductVersion + SimpleProductVersion = $simpleProductVersion + ProductSemanticVersion = $ProductSemanticVersion + ProductVersionWithName = $productVersionWithName + ProductProgFilesDir = $ProductProgFilesDir + FileArchitecture = $fileArchitecture + } + + $buildArguments = New-MsiArgsArray -Argument $arguments + + Start-NativeExecution -VerboseOutputOnError { & $wixPaths.wixHeatExePath dir $staging -dr VersionFolder -cg ApplicationFiles -ag -sfrag -srd -scom -sreg -out $wixFragmentPath -var var.ProductSourcePath $buildArguments -v} # We are verifying that the generated $wixFragmentPath and $FilesWxsPath are functionally the same - Test-FileWxs -FilesWxsPath $FilesWxsPath -HeatFilesWxsPath $wixFragmentPath + Test-FileWxs -FilesWxsPath $FilesWxsPath -HeatFilesWxsPath $wixFragmentPath -FileArchitecture $fileArchitecture if ($isPreview) { @@ -3062,17 +3055,9 @@ function New-MSIPackage Remove-Item -ErrorAction SilentlyContinue $wixObjFragmentPath -Force } - Write-Log "running candle..." - Start-NativeExecution -VerboseOutputOnError { & $wixPaths.wixCandleExePath "$ProductWxsPath" "$FilesWxsPath" -out (Join-Path "$env:Temp" "\\") -ext WixUIExtension -ext WixUtilExtension -arch $ProductTargetArchitecture -dIsPreview="$isPreview" -v} - - Write-Log "running light..." - # suppress ICE61, because we allow same version upgrades - # suppress ICE57, this suppresses an error caused by our shortcut not being installed per user - Start-NativeExecution -VerboseOutputOnError {& $wixPaths.wixLightExePath -sice:ICE61 -sice:ICE57 -out $msiLocationPath -pdbout $msiPdbLocationPath $wixObjProductPath $wixObjFragmentPath -ext WixUIExtension -ext WixUtilExtension } + Start-MsiBuild -WxsFile $ProductWxsPath, $FilesWxsPath -ProductTargetArchitecture $ProductTargetArchitecture -Argument $arguments -MsiLocationPath $msiLocationPath -MsiPdbLocationPath $msiPdbLocationPath Remove-Item -ErrorAction SilentlyContinue $wixFragmentPath -Force - Remove-Item -ErrorAction SilentlyContinue $wixObjProductPath -Force - Remove-Item -ErrorAction SilentlyContinue $wixObjFragmentPath -Force if ((Test-Path $msiLocationPath) -and (Test-Path $msiPdbLocationPath)) { @@ -3090,6 +3075,75 @@ function New-MSIPackage } } +function New-MsiArgsArray { + param( + [Parameter(Mandatory)] + [Hashtable]$Argument + ) + + $buildArguments = @() + foreach ($key in $Argument.Keys) { + $buildArguments += "-d$key=`"$($Argument.$key)`"" + } + + return $buildArguments +} + +function Start-MsiBuild { + param( + [string[]] $WxsFile, + [string[]] $Extension = @('WixUIExtension', 'WixUtilExtension', 'WixBalExtension'), + [string] $ProductTargetArchitecture, + [Hashtable] $Argument, + [string] $MsiLocationPath, + [string] $MsiPdbLocationPath + ) + + $outDir = $env:Temp + + $wixPaths = Get-WixPath + + $extensionArgs = @() + foreach ($extensionName in $Extension) { + $extensionArgs += '-ext' + $extensionArgs += $extensionName + } + + $buildArguments = New-MsiArgsArray -Argument $Argument + + $objectPaths = @() + foreach ($file in $WxsFile) { + $fileName = [system.io.path]::GetFileNameWithoutExtension($file) + $objectPaths += Join-Path $outDir -ChildPath "${filename}.wixobj" + } + + foreach ($file in $objectPaths) { + Remove-Item -ErrorAction SilentlyContinue $file -Force + Remove-Item -ErrorAction SilentlyContinue $file -Force + } + + $resolvedWxsFiles = @() + foreach ($file in $WxsFile) { + $resolvedWxsFiles += (Resolve-Path -Path $file).ProviderPath + } + + Write-Verbose "$resolvedWxsFiles" -Verbose + + Write-Log "running candle..." + Start-NativeExecution -VerboseOutputOnError { & $wixPaths.wixCandleExePath $resolvedWxsFiles -out "$outDir\\" $extensionArgs -arch $ProductTargetArchitecture $buildArguments -v} + + Write-Log "running light..." + # suppress ICE61, because we allow same version upgrades + # suppress ICE57, this suppresses an error caused by our shortcut not being installed per user + Start-NativeExecution -VerboseOutputOnError {& $wixPaths.wixLightExePath -sice:ICE61 -sice:ICE57 -out $msiLocationPath -pdbout $msiPdbLocationPath $objectPaths $extensionArgs } + + foreach($file in $objectPaths) + { + Remove-Item -ErrorAction SilentlyContinue $file -Force + Remove-Item -ErrorAction SilentlyContinue $file -Force + } +} + <# .Synopsis Creates a Windows AppX MSIX package and assumes that the binaries are already built using 'Start-PSBuild'. @@ -3252,12 +3306,14 @@ function Test-FileWxs # File describing the MSI file components generated by heat [ValidateNotNullOrEmpty()] [ValidateScript( {Test-Path $_})] - [string] $HeatFilesWxsPath + [string] $HeatFilesWxsPath, + + [string] $FileArchitecture ) # Update the fileArchitecture in our file to the actual value. Since, the heat file will have the actual value. # Wix will update this automaticaly, but the output is not the same xml - $filesAssetString = (Get-Content -Raw -Path $FilesWxsPath).Replace('$(var.FileArchitecture)',$env:FileArchitecture) + $filesAssetString = (Get-Content -Raw -Path $FilesWxsPath).Replace('$(var.FileArchitecture)', $FileArchitecture) [xml] $filesAssetXml = $filesAssetString [xml] $newFilesAssetXml = $filesAssetString @@ -3318,7 +3374,6 @@ function Test-FileWxs $newComponent = New-XmlElement -XmlDoc $newFilesAssetXml -LocalName 'Component' -Node $filesNode -PassThru -NamespaceUri 'http://schemas.microsoft.com/wix/2006/wi' $componentId = New-WixId -Prefix 'cmp' New-XmlAttribute -XmlDoc $newFilesAssetXml -Element $newComponent -Name 'Id' -Value $componentId - New-XmlAttribute -XmlDoc $newFilesAssetXml -Element $newComponent -Name 'Guid' -Value "{$(New-Guid)}" # Crete new File in Component $newFile = New-XmlElement -XmlDoc $newFilesAssetXml -LocalName 'File' -Node $newComponent -PassThru -NamespaceUri 'http://schemas.microsoft.com/wix/2006/wi' New-XmlAttribute -XmlDoc $newFilesAssetXml -Element $newFile -Name 'Id' -Value (New-WixId -Prefix 'fil')