-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathNewInstallerCommand.cs
119 lines (104 loc) · 3.75 KB
/
NewInstallerCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using PSMSI.Models;
using PSMSI.Wix;
using PSMSI.Xml;
using System;
using System.IO;
using System.Linq;
using System.Management.Automation;
namespace PSMSI
{
[Cmdlet(VerbsCommon.New, "Installer")]
public class NewInstallerCommand : PSCmdlet
{
[Parameter(Mandatory = true)]
public string ProductName { get; set; }
[Parameter()]
public Version Version { get; set; } = new Version(1, 0);
[Parameter()]
public string Manufacturer { get; set; } = "Ironman Software, LLC";
[Parameter(Mandatory = true)]
public Guid UpgradeCode { get; set; }
[Parameter]
public string ProductId { get; set; } = "*";
[Parameter()]
[ValidateSet("x86", "x64", "ia64", "arm", "intel", "intel64")]
public string Platform { get; set; } = "x86";
[Parameter(Mandatory = true)]
public DirectoryInfo OutputDirectory { get; set; }
[Parameter(Mandatory = true)]
public ScriptBlock Content { get; set; }
[Parameter()]
public string HelpLink { get; set; }
[Parameter()]
public string AboutLink { get; set; }
[Parameter()]
public SwitchParameter RequiresElevation { get; set; }
[Parameter()]
public UserInterface UserInterface { get; set; }
[Parameter()]
public FileInfo AddRemoveProgramsIcon { get; set; }
[Parameter()]
public CustomAction[] CustomAction { get; set; }
protected override void ProcessRecord()
{
var installer = new Models.Installer
{
ProductName = ProductName,
Version = Version,
Manufacturer = Manufacturer,
UpgradeCode = UpgradeCode,
Platform = Platform,
OutputDirectory = OutputDirectory,
Content = Content?.Invoke().Select(m => m.BaseObject),
HelpLink = HelpLink,
AboutLink = AboutLink,
RequiresElevation = RequiresElevation,
UserInterface = UserInterface,
AddRemoveProgramsIcon = AddRemoveProgramsIcon,
CustomActions = CustomAction,
ProductId = ProductId
};
if (!OutputDirectory.Exists)
{
OutputDirectory.Create();
}
var wxsFile = Path.Combine(OutputDirectory.FullName, $"{ProductName}.{Version}.{Platform}.wxs");
var generator = new WixXmlGenerator();
var document = generator.Generate(installer);
document.Save(wxsFile);
var wxsObjFile = Path.Combine(OutputDirectory.FullName, $"{ProductName}.{Version}.{Platform}.wxsobj");
var msiFile = Path.Combine(OutputDirectory.FullName, $"{ProductName}.{Version}.{Platform}.msi");
var candle = new Candle();
var candleOptions = new CandleOption
{
WxsFile = wxsFile,
WxsObjFile = wxsObjFile
};
var result = candle.Run(candleOptions);
if (!result.Success)
{
throw new Exception(result.Output);
}
else
{
WriteVerbose(result.Output);
}
var light = new Light();
var lightOptions = new LightOptions
{
MsiFileName = msiFile,
OutputDirectory = OutputDirectory.FullName,
WixObjFile = wxsObjFile
};
result = light.Run(lightOptions);
if (!result.Success)
{
throw new Exception(result.Output);
}
else
{
WriteVerbose(result.Output);
}
}
}
}