2016-03-07 12:20:50 -08:00
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.IO.Compression ;
using System.Runtime.InteropServices ;
using Microsoft.DotNet.Cli.Build.Framework ;
using Microsoft.Extensions.PlatformAbstractions ;
using static Microsoft . DotNet . Cli . Build . Framework . BuildHelpers ;
namespace Microsoft.DotNet.Cli.Build
{
public class MsiTargets
{
private const string ENGINE = "engine.exe" ;
private static string WixRoot
{
get
{
return Path . Combine ( Dirs . Output , "WixTools" ) ;
}
}
2016-03-08 13:39:41 -08:00
private static string SdkMsi { get ; set ; }
2016-03-07 12:20:50 -08:00
2016-03-08 13:39:41 -08:00
private static string SdkBundle { get ; set ; }
2016-03-07 12:20:50 -08:00
2016-03-08 15:22:33 -08:00
private static string SharedHostMsi { get ; set ; }
2016-03-08 19:32:31 -08:00
private static string SharedFrameworkMsi { get ; set ; }
2016-03-07 12:20:50 -08:00
private static string Engine { get ; set ; }
2016-03-07 14:52:41 -08:00
private static string MsiVersion { get ; set ; }
private static string CliVersion { get ; set ; }
private static string Arch { get ; } = CurrentArchitecture . Current . ToString ( ) ;
private static string Channel { get ; set ; }
2016-03-07 12:20:50 -08:00
private static void AcquireWix ( BuildTargetContext c )
{
if ( File . Exists ( Path . Combine ( WixRoot , "candle.exe" ) ) )
{
return ;
}
Directory . CreateDirectory ( WixRoot ) ;
c . Info ( "Downloading WixTools.." ) ;
// Download Wix version 3.10.2 - https://wix.codeplex.com/releases/view/619491
Cmd ( "powershell" , "-NoProfile" , "-NoLogo" ,
$"Invoke-WebRequest -Uri https://wix.codeplex.com/downloads/get/1540241 -Method Get -OutFile {WixRoot}\\WixTools.zip" )
. Execute ( )
. EnsureSuccessful ( ) ;
c . Info ( "Extracting WixTools.." ) ;
ZipFile . ExtractToDirectory ( $"{WixRoot}\\WixTools.zip" , WixRoot ) ;
}
[Target]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult InitMsi ( BuildTargetContext c )
{
2016-03-16 17:54:44 -07:00
SdkBundle = c . BuildContext . Get < string > ( "CombinedFrameworkSDKHostInstallerFile" ) ;
2016-03-08 13:39:41 -08:00
SdkMsi = Path . ChangeExtension ( SdkBundle , "msi" ) ;
Engine = Path . Combine ( Path . GetDirectoryName ( SdkBundle ) , ENGINE ) ;
2016-03-07 14:52:41 -08:00
2016-03-08 15:22:33 -08:00
SharedHostMsi = Path . ChangeExtension ( c . BuildContext . Get < string > ( "SharedHostInstallerFile" ) , "msi" ) ;
2016-03-08 19:32:31 -08:00
SharedFrameworkMsi = Path . ChangeExtension ( c . BuildContext . Get < string > ( "SharedFrameworkInstallerFile" ) , "msi" ) ;
2016-03-08 15:22:33 -08:00
2016-03-07 14:52:41 -08:00
var buildVersion = c . BuildContext . Get < BuildVersion > ( "BuildVersion" ) ;
MsiVersion = buildVersion . GenerateMsiVersion ( ) ;
CliVersion = buildVersion . SimpleVersion ;
Channel = c . BuildContext . Get < string > ( "Channel" ) ;
2016-03-07 12:20:50 -08:00
AcquireWix ( c ) ;
return c . Success ( ) ;
}
[ Target ( nameof ( MsiTargets . InitMsi ) ,
2016-03-08 15:22:33 -08:00
nameof ( GenerateDotnetSharedHostMsi ) ,
2016-03-08 19:32:31 -08:00
nameof ( GenerateDotnetSharedFrameworkMsi ) ,
2016-03-08 13:39:41 -08:00
nameof ( GenerateCliSdkMsi ) ) ]
2016-03-07 12:20:50 -08:00
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult GenerateMsis ( BuildTargetContext c )
{
return c . Success ( ) ;
}
[Target]
[BuildPlatforms(BuildPlatform.Windows)]
2016-03-08 13:39:41 -08:00
public static BuildTargetResult GenerateCliSdkMsi ( BuildTargetContext c )
2016-03-07 12:20:50 -08:00
{
2016-03-14 18:54:45 -07:00
var cliSdkRoot = c . BuildContext . Get < string > ( "CLISDKRoot" ) ;
2016-03-07 12:20:50 -08:00
Cmd ( "powershell" , "-NoProfile" , "-NoLogo" ,
2016-03-07 14:52:41 -08:00
Path . Combine ( Dirs . RepoRoot , "packaging" , "windows" , "generatemsi.ps1" ) ,
2016-03-14 18:54:45 -07:00
cliSdkRoot , SdkMsi , WixRoot , MsiVersion , CliVersion , Arch , Channel )
2016-03-07 12:20:50 -08:00
. Execute ( )
. EnsureSuccessful ( ) ;
return c . Success ( ) ;
}
2016-03-08 21:52:34 -08:00
[Target]
2016-03-07 12:20:50 -08:00
[BuildPlatforms(BuildPlatform.Windows)]
2016-03-08 15:22:33 -08:00
public static BuildTargetResult GenerateDotnetSharedHostMsi ( BuildTargetContext c )
2016-03-07 12:20:50 -08:00
{
2016-03-08 15:22:33 -08:00
var inputDir = c . BuildContext . Get < string > ( "SharedHostPublishRoot" ) ;
var wixObjRoot = Path . Combine ( Dirs . Output , "obj" , "wix" , "sharedhost" ) ;
if ( Directory . Exists ( wixObjRoot ) )
{
2016-03-15 14:06:54 -07:00
Utils . DeleteDirectory ( wixObjRoot ) ;
2016-03-08 15:22:33 -08:00
}
Directory . CreateDirectory ( wixObjRoot ) ;
Cmd ( "powershell" , "-NoProfile" , "-NoLogo" ,
Path . Combine ( Dirs . RepoRoot , "packaging" , "host" , "windows" , "generatemsi.ps1" ) ,
inputDir , SharedHostMsi , WixRoot , MsiVersion , CliVersion , Arch , wixObjRoot )
. Execute ( )
. EnsureSuccessful ( ) ;
2016-03-07 12:20:50 -08:00
return c . Success ( ) ;
}
2016-03-08 21:52:34 -08:00
[Target]
2016-03-07 12:20:50 -08:00
[BuildPlatforms(BuildPlatform.Windows)]
2016-03-08 19:32:31 -08:00
public static BuildTargetResult GenerateDotnetSharedFrameworkMsi ( BuildTargetContext c )
2016-03-07 12:20:50 -08:00
{
2016-03-08 19:32:31 -08:00
var inputDir = c . BuildContext . Get < string > ( "SharedFrameworkPublishRoot" ) ;
2016-03-16 17:54:44 -07:00
var sharedFrameworkNuGetName = Monikers . SharedFrameworkName ;
2016-03-08 19:32:31 -08:00
var sharedFrameworkNuGetVersion = c . BuildContext . Get < string > ( "SharedFrameworkNugetVersion" ) ;
var upgradeCode = Utils . GenerateGuidFromName ( $"{sharedFrameworkNuGetName}-{sharedFrameworkNuGetVersion}-{Arch}" ) . ToString ( ) . ToUpper ( ) ;
var wixObjRoot = Path . Combine ( Dirs . Output , "obj" , "wix" , "sharedframework" ) ;
if ( Directory . Exists ( wixObjRoot ) )
{
2016-03-15 14:06:54 -07:00
Utils . DeleteDirectory ( wixObjRoot ) ;
2016-03-08 19:32:31 -08:00
}
Directory . CreateDirectory ( wixObjRoot ) ;
Cmd ( "powershell" , "-NoProfile" , "-NoLogo" ,
Path . Combine ( Dirs . RepoRoot , "packaging" , "sharedframework" , "windows" , "generatemsi.ps1" ) ,
inputDir , SharedFrameworkMsi , WixRoot , MsiVersion , sharedFrameworkNuGetName , sharedFrameworkNuGetVersion , upgradeCode , Arch , wixObjRoot )
. Execute ( )
. EnsureSuccessful ( ) ;
2016-03-07 12:20:50 -08:00
return c . Success ( ) ;
}
[Target(nameof(MsiTargets.InitMsi))]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult GenerateBundle ( BuildTargetContext c )
{
Cmd ( "powershell" , "-NoProfile" , "-NoLogo" ,
2016-03-07 14:52:41 -08:00
Path . Combine ( Dirs . RepoRoot , "packaging" , "windows" , "generatebundle.ps1" ) ,
2016-03-14 18:54:45 -07:00
SdkMsi , SharedFrameworkMsi , SharedHostMsi , SdkBundle , WixRoot , MsiVersion , CliVersion , Arch , Channel )
2016-03-07 14:52:41 -08:00
. EnvironmentVariable ( "Stage2Dir" , Dirs . Stage2 )
2016-03-07 12:20:50 -08:00
. Execute ( )
. EnsureSuccessful ( ) ;
return c . Success ( ) ;
}
[Target(nameof(MsiTargets.InitMsi))]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult ExtractEngineFromBundle ( BuildTargetContext c )
{
2016-03-08 13:39:41 -08:00
Cmd ( $"{WixRoot}\\insignia.exe" , "-ib" , SdkBundle , "-o" , Engine )
2016-03-07 12:20:50 -08:00
. Execute ( )
. EnsureSuccessful ( ) ;
return c . Success ( ) ;
}
[Target(nameof(MsiTargets.InitMsi))]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult ReattachEngineToBundle ( BuildTargetContext c )
{
2016-03-08 13:39:41 -08:00
Cmd ( $"{WixRoot}\\insignia.exe" , "-ab" , Engine , SdkBundle , "-o" , SdkBundle )
2016-03-07 12:20:50 -08:00
. Execute ( )
. EnsureSuccessful ( ) ;
return c . Success ( ) ;
}
}
}