@@ -50,6 +50,8 @@ function Find-EnvironmentVariables([string[]] $variables) {
5050 }
5151}
5252
53+ Find-Dependencies @ (" dotnet.exe" , " wix.exe" )
54+
5355if ($sign ) {
5456 Write-Host " Signing is enabled"
5557 Find-Dependencies java
@@ -97,7 +99,8 @@ if (Test-Path $outputPath.Replace(".exe", ".wixpdb")) {
9799}
98100
99101# Create a publish directory
100- $buildPath = Join-Path $repoRoot " publish\buildtemp-$ ( $version ) -$ ( $arch ) "
102+ $publishDir = Join-Path $repoRoot " publish"
103+ $buildPath = Join-Path $publishDir " buildtemp-$ ( $version ) -$ ( $arch ) "
101104if (Test-Path $buildPath ) {
102105 Remove-Item - Recurse - Force $buildPath
103106}
@@ -164,7 +167,39 @@ Add-CoderSignature $msiOutputPath
164167 -- msi- path $msiOutputPath `
165168 -- logo- png " scripts\files\logo.png"
166169if ($LASTEXITCODE -ne 0 ) { throw " Failed to build bootstrapper" }
167- Add-CoderSignature $outputPath
170+
171+ # Sign the bootstrapper, which is not as simple as just signing the exe.
172+ if ($sign ) {
173+ $burnIntermediate = Join-Path $publishDir " burn-intermediate-$ ( $version ) -$ ( $arch ) "
174+ New-Item - ItemType Directory - Path $burnIntermediate - Force
175+ $burnEngine = Join-Path $publishDir " burn-engine-$ ( $version ) -$ ( $arch ) .exe"
176+
177+ # Move the current output path
178+ $unsignedOutputPath = Join-Path (Split-Path $outputPath - Parent) (" UNSIGNED-" + (Split-Path $outputPath - Leaf))
179+ Move-Item $outputPath $unsignedOutputPath
180+
181+ # Extract the engine from the bootstrapper
182+ & wix.exe burn detach $unsignedOutputPath - intermediateFolder $burnIntermediate - engine $burnEngine
183+ if ($LASTEXITCODE -ne 0 ) { throw " Failed to extract engine from bootstrapper" }
184+
185+ # Sign the engine
186+ Add-CoderSignature $burnEngine
187+
188+ # Re-attach the signed engine to the bootstrapper
189+ & wix.exe burn reattach $unsignedOutputPath - intermediateFolder $burnIntermediate - engine $burnEngine - out $outputPath
190+ if ($LASTEXITCODE -ne 0 ) { throw " Failed to re-attach signed engine to bootstrapper" }
191+ if (! (Test-Path $outputPath )) { throw " Failed to create reattached bootstrapper at $outputPath " }
192+
193+ # Now sign the output path
194+ Add-CoderSignature $outputPath
195+
196+ # Clean up the intermediate files
197+ if (! $keepBuildTemp ) {
198+ Remove-Item - Force $unsignedOutputPath
199+ Remove-Item - Recurse - Force $burnIntermediate
200+ Remove-Item - Force $burnEngine
201+ }
202+ }
168203
169204if (! $keepBuildTemp ) {
170205 Remove-Item - Recurse - Force $buildPath
0 commit comments