From fb61e69a79c19035aaae8f6704f75791a1208047 Mon Sep 17 00:00:00 2001 From: Sridhar Periyasamy Date: Tue, 17 Nov 2015 00:39:46 -0800 Subject: [PATCH] First pass at building Windows MSI for the dotnet CLI repo. - Use the heat tool to harvest the stage2 dir and create install-files.wxs - dotnet.wxs contains the XML code which is constant across builds for an MSI. - Use Candle and Light to generate the MSI from install-files.wxs and dotnet.wxs. Default Install Location - %ProgramFiles%/dotnet. Adds \bin %PATH% Creates %DOTNET_HOME% pointing to --- packaging/windows/WiXTools/Program.cs | 14 +++ packaging/windows/WiXTools/README.md | 3 + packaging/windows/WiXTools/project.json | 13 +++ packaging/windows/dotnet.wxs | 33 ++++++ packaging/windows/generatemsi.ps1 | 142 ++++++++++++++++++++++++ scripts/build.ps1 | 5 + 6 files changed, 210 insertions(+) create mode 100644 packaging/windows/WiXTools/Program.cs create mode 100644 packaging/windows/WiXTools/README.md create mode 100644 packaging/windows/WiXTools/project.json create mode 100644 packaging/windows/dotnet.wxs create mode 100644 packaging/windows/generatemsi.ps1 diff --git a/packaging/windows/WiXTools/Program.cs b/packaging/windows/WiXTools/Program.cs new file mode 100644 index 000000000..3825adfd4 --- /dev/null +++ b/packaging/windows/WiXTools/Program.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace WiX.Toolset.2015 +{ + public class Program + { + public static int Main(string[] args) + { + // Temporary and bogus. Just needed so we can publish this + return 1; + } + } +} diff --git a/packaging/windows/WiXTools/README.md b/packaging/windows/WiXTools/README.md new file mode 100644 index 000000000..3bcef45b8 --- /dev/null +++ b/packaging/windows/WiXTools/README.md @@ -0,0 +1,3 @@ +# WiX.Toolset.2015 + +This is a utility project that brings the Wix Tools down and lets us publish it as though it were an app. Do NOT add any C# code to it! It is not designed to actually be compiled as an assembly, it's just used for its dependencies. diff --git a/packaging/windows/WiXTools/project.json b/packaging/windows/WiXTools/project.json new file mode 100644 index 000000000..87f40765a --- /dev/null +++ b/packaging/windows/WiXTools/project.json @@ -0,0 +1,13 @@ +{ + "compilationOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "WiX.Toolset.2015": "3.10.0.1503" + }, + + "frameworks": { + "dnxcore50": { } + } +} diff --git a/packaging/windows/dotnet.wxs b/packaging/windows/dotnet.wxs new file mode 100644 index 000000000..80e739728 --- /dev/null +++ b/packaging/windows/dotnet.wxs @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packaging/windows/generatemsi.ps1 b/packaging/windows/generatemsi.ps1 new file mode 100644 index 000000000..4240cc949 --- /dev/null +++ b/packaging/windows/generatemsi.ps1 @@ -0,0 +1,142 @@ +# Copyright (c) .NET Foundation and contributors. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +param( + [string]$inputDir = $(throw "Specify the full path to the directory which needs to be harvested") +) + +. "$PSScriptRoot\..\..\scripts\_common.ps1" + +$DotnetMSIOutput = "" +$WixRoot = "" +$InstallFileswsx = "install-files.wxs" +$InstallFilesWixobj = "install-files.wixobj" + +function AcquireWixTools +{ + pushd "$Stage2Dir\bin" + + Write-Host Restoring Wixtools.. + + $result = Join-Path $env:TEMP WiX + + .\dotnet restore $RepoRoot\packaging\windows\WiXTools --packages $result | Out-Null + + if($LastExitCode -ne 0) + { + $result = "" + Write-Host "dotnet restore failed with exit code $LastExitCode." + } + else + { + $result = Join-Path $result WiX.Toolset.2015\3.10.0.1503\tools\wix + } + + popd + return $result +} + +function RunHeat +{ + $result = $true + pushd "$WixRoot" + + Write-Host Running heat.. + + .\heat.exe dir `"$inputDir`" -template fragment -sreg -gg -var var.DotnetSrc -cg InstallFiles -srd -dr DOTNETHOME -out $InstallFileswsx | Out-Null + + if($LastExitCode -ne 0) + { + $result = $false + Write-Host "Heat failed with exit code $LastExitCode." + } + + popd + return $result +} + +function RunCandle +{ + $result = $true + pushd "$WixRoot" + + Write-Host Running candle.. + + .\candle.exe -dDotnetSrc="$inputDir" -dMicrosoftEula="$RepoRoot\packaging\osx\resources\en.lproj\eula.rtf" "$RepoRoot\packaging\windows\dotnet.wxs" $InstallFileswsx | Out-Null + + if($LastExitCode -ne 0) + { + $result = $false + Write-Host "Candle failed with exit code $LastExitCode." + } + + popd + return $result +} + +function RunLight +{ + $result = $true + pushd "$WixRoot" + + Write-Host Running light.. + + .\light -ext WixUIExtension -cultures:en-us dotnet.wixobj $InstallFilesWixobj -out $DotnetMSIOutput | Out-Null + + if($LastExitCode -ne 0) + { + $result = $false + Write-Host "Light failed with exit code $LastExitCode." + } + + popd + return $result +} + +if(!(Test-Path $inputDir)) +{ + throw "$inputDir not found" +} + +if(!(Test-Path $PackageDir)) +{ + mkdir $PackageDir | Out-Null +} + +$DotnetMSIOutput = Join-Path $PackageDir "dotnet-win-x64.$env:DOTNET_BUILD_VERSION.msi" + +Write-Host "Creating dotnet MSI at $DotnetMSIOutput" + +$WixRoot = AcquireWixTools + + +if([string]::IsNullOrEmpty($WixRoot)) +{ + return -1 +} + +if(-Not (RunHeat)) +{ + Write-Host Fooooobar + return -1 +} + +if(-Not (RunCandle)) +{ + return -1 +} + +if(-Not (RunLight)) +{ + return -1 +} + +if(!(Test-Path $DotnetMSIOutput)) +{ + throw "Unable to create the dotnet msi." + return -1 +} + +Write-Host -ForegroundColor Green "Successfully create dotnet MSI - $DotnetMSIOutput" + +return 0 diff --git a/scripts/build.ps1 b/scripts/build.ps1 index ca0f3abdb..3af5ca963 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -6,6 +6,8 @@ param( [string]$Configuration="Debug") +. "$PSScriptRoot\_common.ps1" + $ErrorActionPreference="Stop" # Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot @@ -31,3 +33,6 @@ Write-Host -ForegroundColor Green "*** Building dotnet tools version $($env:DOTN Write-Host -ForegroundColor Green "*** Packaging dotnet ***" & "$PSScriptRoot\package\package.ps1" + +Write-Host -ForegroundColor Green "*** Generating dotnet MSI ***" +& "$RepoRoot\packaging\windows\generatemsi.ps1" $Stage2Dir