2016-03-07 20:20:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
2016-03-18 21:36:50 +00:00
|
|
|
|
using System.Net.Http;
|
2016-03-07 20:20:50 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using Microsoft.DotNet.Cli.Build.Framework;
|
2016-04-28 23:30:32 +00:00
|
|
|
|
using Microsoft.DotNet.InternalAbstractions;
|
2016-03-07 20:20:50 +00:00
|
|
|
|
|
|
|
|
|
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Build
|
|
|
|
|
{
|
|
|
|
|
public class MsiTargets
|
|
|
|
|
{
|
|
|
|
|
private const string ENGINE = "engine.exe";
|
|
|
|
|
|
2016-03-18 21:36:50 +00:00
|
|
|
|
private const string WixVersion = "3.10.2";
|
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
private static string WixRoot
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-03-18 21:36:50 +00:00
|
|
|
|
return Path.Combine(Dirs.Output, $"WixTools.{WixVersion}");
|
2016-03-07 20:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 21:39:41 +00:00
|
|
|
|
private static string SdkMsi { get; set; }
|
2016-03-07 20:20:50 +00:00
|
|
|
|
|
2016-03-08 21:39:41 +00:00
|
|
|
|
private static string SdkBundle { get; set; }
|
2016-03-07 20:20:50 +00:00
|
|
|
|
|
2016-03-08 23:22:33 +00:00
|
|
|
|
private static string SharedHostMsi { get; set; }
|
|
|
|
|
|
2016-03-09 03:32:31 +00:00
|
|
|
|
private static string SharedFrameworkMsi { get; set; }
|
|
|
|
|
|
2016-03-18 00:54:01 +00:00
|
|
|
|
private static string SharedFrameworkBundle { get; set; }
|
|
|
|
|
|
2016-03-31 17:02:12 +00:00
|
|
|
|
private static string SdkEngine { get; set; }
|
|
|
|
|
|
|
|
|
|
private static string SharedFrameworkEngine { get; set; }
|
2016-03-07 20:20:50 +00:00
|
|
|
|
|
2016-03-07 22:52:41 +00:00
|
|
|
|
private static string MsiVersion { get; set; }
|
|
|
|
|
|
2016-04-15 19:11:10 +00:00
|
|
|
|
private static string CliDisplayVersion { get; set; }
|
2016-03-07 22:52:41 +00:00
|
|
|
|
|
2016-04-15 19:11:10 +00:00
|
|
|
|
private static string CliNugetVersion { get; set; }
|
2016-03-07 22:52:41 +00:00
|
|
|
|
|
2016-04-15 19:11:10 +00:00
|
|
|
|
private static string Arch { get; } = CurrentArchitecture.Current.ToString();
|
2016-03-07 22:52:41 +00:00
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
private static void AcquireWix(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(Path.Combine(WixRoot, "candle.exe")))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(WixRoot);
|
|
|
|
|
|
|
|
|
|
c.Info("Downloading WixTools..");
|
2016-03-18 21:36:50 +00:00
|
|
|
|
|
|
|
|
|
DownloadFile($"https://dotnetcli.blob.core.windows.net/build/wix/wix.{WixVersion}.zip", Path.Combine(WixRoot, "WixTools.zip"));
|
2016-03-07 20:20:50 +00:00
|
|
|
|
|
|
|
|
|
c.Info("Extracting WixTools..");
|
2016-03-18 21:36:50 +00:00
|
|
|
|
ZipFile.ExtractToDirectory(Path.Combine(WixRoot, "WixTools.zip"), WixRoot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void DownloadFile(string uri, string destinationPath)
|
|
|
|
|
{
|
|
|
|
|
using (var httpClient = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
var getTask = httpClient.GetStreamAsync(uri);
|
|
|
|
|
|
|
|
|
|
using (var outStream = File.OpenWrite(destinationPath))
|
|
|
|
|
{
|
|
|
|
|
getTask.Result.CopyTo(outStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-07 20:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
|
|
|
|
public static BuildTargetResult InitMsi(BuildTargetContext c)
|
|
|
|
|
{
|
2016-03-17 00:54:44 +00:00
|
|
|
|
SdkBundle = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile");
|
2016-03-08 21:39:41 +00:00
|
|
|
|
SdkMsi = Path.ChangeExtension(SdkBundle, "msi");
|
2016-03-31 17:02:12 +00:00
|
|
|
|
SdkEngine = GetEngineName(SdkBundle);
|
2016-03-07 22:52:41 +00:00
|
|
|
|
|
2016-03-18 00:54:01 +00:00
|
|
|
|
SharedFrameworkBundle = c.BuildContext.Get<string>("CombinedFrameworkHostInstallerFile");
|
2016-03-08 23:22:33 +00:00
|
|
|
|
SharedHostMsi = Path.ChangeExtension(c.BuildContext.Get<string>("SharedHostInstallerFile"), "msi");
|
2016-03-09 03:32:31 +00:00
|
|
|
|
SharedFrameworkMsi = Path.ChangeExtension(c.BuildContext.Get<string>("SharedFrameworkInstallerFile"), "msi");
|
2016-03-31 17:02:12 +00:00
|
|
|
|
SharedFrameworkEngine = GetEngineName(SharedFrameworkBundle);
|
2016-03-08 23:22:33 +00:00
|
|
|
|
|
2016-03-07 22:52:41 +00:00
|
|
|
|
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
|
|
|
|
|
MsiVersion = buildVersion.GenerateMsiVersion();
|
2016-04-15 19:11:10 +00:00
|
|
|
|
CliDisplayVersion = buildVersion.SimpleVersion;
|
|
|
|
|
CliNugetVersion = buildVersion.NuGetVersion;
|
2016-03-07 22:52:41 +00:00
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
AcquireWix(c);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target(nameof(MsiTargets.InitMsi),
|
2016-03-08 23:22:33 +00:00
|
|
|
|
nameof(GenerateDotnetSharedHostMsi),
|
2016-03-09 03:32:31 +00:00
|
|
|
|
nameof(GenerateDotnetSharedFrameworkMsi),
|
2016-03-08 21:39:41 +00:00
|
|
|
|
nameof(GenerateCliSdkMsi))]
|
2016-03-07 20:20:50 +00:00
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
|
|
|
|
public static BuildTargetResult GenerateMsis(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 00:54:01 +00:00
|
|
|
|
[Target(nameof(MsiTargets.InitMsi),
|
|
|
|
|
nameof(GenerateCliSdkBundle),
|
|
|
|
|
nameof(GenerateSharedFxBundle))]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
|
|
|
|
public static BuildTargetResult GenerateBundles(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
[Target]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
2016-03-08 21:39:41 +00:00
|
|
|
|
public static BuildTargetResult GenerateCliSdkMsi(BuildTargetContext c)
|
2016-03-07 20:20:50 +00:00
|
|
|
|
{
|
2016-03-15 01:54:45 +00:00
|
|
|
|
var cliSdkRoot = c.BuildContext.Get<string>("CLISDKRoot");
|
2016-03-25 01:05:14 +00:00
|
|
|
|
var upgradeCode = Utils.GenerateGuidFromName(SdkMsi).ToString().ToUpper();
|
2016-04-28 00:20:52 +00:00
|
|
|
|
var cliSdkBrandName = $"'{Monikers.CLISdkBrandName}'";
|
2016-03-25 01:05:14 +00:00
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
Cmd("powershell", "-NoProfile", "-NoLogo",
|
2016-03-18 00:54:01 +00:00
|
|
|
|
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "clisdk", "generatemsi.ps1"),
|
2016-04-27 01:00:02 +00:00
|
|
|
|
cliSdkRoot, SdkMsi, WixRoot, cliSdkBrandName, MsiVersion, CliDisplayVersion, CliNugetVersion, upgradeCode, Arch)
|
2016-03-07 20:20:50 +00:00
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 05:52:34 +00:00
|
|
|
|
[Target]
|
2016-03-07 20:20:50 +00:00
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
2016-03-08 23:22:33 +00:00
|
|
|
|
public static BuildTargetResult GenerateDotnetSharedHostMsi(BuildTargetContext c)
|
2016-03-07 20:20:50 +00:00
|
|
|
|
{
|
2016-03-08 23:22:33 +00:00
|
|
|
|
var inputDir = c.BuildContext.Get<string>("SharedHostPublishRoot");
|
|
|
|
|
var wixObjRoot = Path.Combine(Dirs.Output, "obj", "wix", "sharedhost");
|
2016-04-27 01:00:02 +00:00
|
|
|
|
var sharedHostBrandName = $"'{Monikers.SharedHostBrandName}'";
|
2016-03-08 23:22:33 +00:00
|
|
|
|
|
|
|
|
|
if (Directory.Exists(wixObjRoot))
|
|
|
|
|
{
|
2016-03-15 21:06:54 +00:00
|
|
|
|
Utils.DeleteDirectory(wixObjRoot);
|
2016-03-08 23:22:33 +00:00
|
|
|
|
}
|
|
|
|
|
Directory.CreateDirectory(wixObjRoot);
|
|
|
|
|
|
|
|
|
|
Cmd("powershell", "-NoProfile", "-NoLogo",
|
2016-03-18 00:54:01 +00:00
|
|
|
|
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "host", "generatemsi.ps1"),
|
2016-04-27 01:00:02 +00:00
|
|
|
|
inputDir, SharedHostMsi, WixRoot, sharedHostBrandName, MsiVersion, CliDisplayVersion, CliNugetVersion, Arch, wixObjRoot)
|
2016-03-08 23:22:33 +00:00
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
2016-03-07 20:20:50 +00:00
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 05:52:34 +00:00
|
|
|
|
[Target]
|
2016-03-07 20:20:50 +00:00
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
2016-03-09 03:32:31 +00:00
|
|
|
|
public static BuildTargetResult GenerateDotnetSharedFrameworkMsi(BuildTargetContext c)
|
2016-03-07 20:20:50 +00:00
|
|
|
|
{
|
2016-03-09 03:32:31 +00:00
|
|
|
|
var inputDir = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
|
2016-03-17 00:54:44 +00:00
|
|
|
|
var sharedFrameworkNuGetName = Monikers.SharedFrameworkName;
|
2016-03-09 03:32:31 +00:00
|
|
|
|
var sharedFrameworkNuGetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
2016-03-25 01:05:14 +00:00
|
|
|
|
var msiVerison = sharedFrameworkNuGetVersion.Split('-')[0];
|
|
|
|
|
var upgradeCode = Utils.GenerateGuidFromName(SharedFrameworkMsi).ToString().ToUpper();
|
2016-03-09 03:32:31 +00:00
|
|
|
|
var wixObjRoot = Path.Combine(Dirs.Output, "obj", "wix", "sharedframework");
|
2016-04-27 01:00:02 +00:00
|
|
|
|
var sharedFxBrandName = $"'{Monikers.SharedFxBrandName}'";
|
2016-03-09 03:32:31 +00:00
|
|
|
|
|
|
|
|
|
if (Directory.Exists(wixObjRoot))
|
|
|
|
|
{
|
2016-03-15 21:06:54 +00:00
|
|
|
|
Utils.DeleteDirectory(wixObjRoot);
|
2016-03-09 03:32:31 +00:00
|
|
|
|
}
|
|
|
|
|
Directory.CreateDirectory(wixObjRoot);
|
|
|
|
|
|
|
|
|
|
Cmd("powershell", "-NoProfile", "-NoLogo",
|
2016-03-18 00:54:01 +00:00
|
|
|
|
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "sharedframework", "generatemsi.ps1"),
|
2016-04-27 01:00:02 +00:00
|
|
|
|
inputDir, SharedFrameworkMsi, WixRoot, sharedFxBrandName, msiVerison, sharedFrameworkNuGetName, sharedFrameworkNuGetVersion, upgradeCode, Arch, wixObjRoot)
|
2016-03-09 03:32:31 +00:00
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
2016-03-07 20:20:50 +00:00
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Target(nameof(MsiTargets.InitMsi))]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
2016-03-18 00:54:01 +00:00
|
|
|
|
public static BuildTargetResult GenerateCliSdkBundle(BuildTargetContext c)
|
2016-03-07 20:20:50 +00:00
|
|
|
|
{
|
2016-03-25 01:05:14 +00:00
|
|
|
|
var upgradeCode = Utils.GenerateGuidFromName(SdkBundle).ToString().ToUpper();
|
2016-04-28 00:20:52 +00:00
|
|
|
|
var cliSdkBrandName = $"'{Monikers.CLISdkBrandName}'";
|
2016-03-25 01:05:14 +00:00
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
Cmd("powershell", "-NoProfile", "-NoLogo",
|
2016-03-18 00:54:01 +00:00
|
|
|
|
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "clisdk", "generatebundle.ps1"),
|
2016-04-27 01:00:02 +00:00
|
|
|
|
SdkMsi, SharedFrameworkMsi, SharedHostMsi, SdkBundle, WixRoot, cliSdkBrandName, MsiVersion, CliDisplayVersion, CliNugetVersion, upgradeCode, Arch)
|
2016-03-07 22:52:41 +00:00
|
|
|
|
.EnvironmentVariable("Stage2Dir", Dirs.Stage2)
|
2016-03-07 20:20:50 +00:00
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 00:54:01 +00:00
|
|
|
|
[Target(nameof(MsiTargets.InitMsi))]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
|
|
|
|
public static BuildTargetResult GenerateSharedFxBundle(BuildTargetContext c)
|
|
|
|
|
{
|
|
|
|
|
var sharedFrameworkNuGetName = Monikers.SharedFrameworkName;
|
|
|
|
|
var sharedFrameworkNuGetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
2016-03-25 01:05:14 +00:00
|
|
|
|
var upgradeCode = Utils.GenerateGuidFromName(SharedFrameworkBundle).ToString().ToUpper();
|
2016-04-27 01:00:02 +00:00
|
|
|
|
var sharedFxBrandName = $"'{Monikers.SharedFxBrandName}'";
|
2016-03-18 00:54:01 +00:00
|
|
|
|
|
|
|
|
|
Cmd("powershell", "-NoProfile", "-NoLogo",
|
|
|
|
|
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "sharedframework", "generatebundle.ps1"),
|
2016-04-27 01:00:02 +00:00
|
|
|
|
SharedFrameworkMsi, SharedHostMsi, SharedFrameworkBundle, WixRoot, sharedFxBrandName, MsiVersion, CliDisplayVersion, sharedFrameworkNuGetName, sharedFrameworkNuGetVersion, upgradeCode, Arch)
|
2016-03-18 00:54:01 +00:00
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 20:20:50 +00:00
|
|
|
|
[Target(nameof(MsiTargets.InitMsi))]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
|
|
|
|
public static BuildTargetResult ExtractEngineFromBundle(BuildTargetContext c)
|
|
|
|
|
{
|
2016-03-31 17:02:12 +00:00
|
|
|
|
ExtractEngineFromBundleHelper(SdkBundle, SdkEngine);
|
|
|
|
|
ExtractEngineFromBundleHelper(SharedFrameworkBundle, SharedFrameworkEngine);
|
2016-03-07 20:20:50 +00:00
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Target(nameof(MsiTargets.InitMsi))]
|
|
|
|
|
[BuildPlatforms(BuildPlatform.Windows)]
|
|
|
|
|
public static BuildTargetResult ReattachEngineToBundle(BuildTargetContext c)
|
|
|
|
|
{
|
2016-03-31 17:02:12 +00:00
|
|
|
|
ReattachEngineToBundleHelper(SdkBundle, SdkEngine);
|
|
|
|
|
ReattachEngineToBundleHelper(SharedFrameworkBundle, SharedFrameworkEngine);
|
|
|
|
|
return c.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetEngineName(string bundle)
|
|
|
|
|
{
|
|
|
|
|
var engine = $"{Path.GetFileNameWithoutExtension(bundle)}-{ENGINE}";
|
|
|
|
|
return Path.Combine(Path.GetDirectoryName(bundle), engine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ExtractEngineFromBundleHelper(string bundle, string engine)
|
|
|
|
|
{
|
|
|
|
|
Cmd($"{WixRoot}\\insignia.exe", "-ib", bundle, "-o", engine)
|
2016-03-07 20:20:50 +00:00
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
2016-03-31 17:02:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ReattachEngineToBundleHelper(string bundle, string engine)
|
|
|
|
|
{
|
|
|
|
|
Cmd($"{WixRoot}\\insignia.exe", "-ab", engine, bundle, "-o", bundle)
|
|
|
|
|
.Execute()
|
|
|
|
|
.EnsureSuccessful();
|
|
|
|
|
|
|
|
|
|
File.Delete(engine);
|
2016-03-07 20:20:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|