-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-package.ps1
81 lines (65 loc) · 2.55 KB
/
build-package.ps1
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
param
(
[Parameter(Mandatory = $true)]
[string]$ProjectDir,
[Parameter(Mandatory = $true)]
[string]$PublishDir,
[Parameter(Mandatory = $true)]
[string]$SolutionDir,
[Parameter(Mandatory = $true)]
[string]$AssemblyName,
[Parameter(Mandatory = $true)]
[string]$Product,
[Parameter(Mandatory = $true)]
[string]$RuntimeIdentifier,
[Parameter(Mandatory = $true)]
[string]$Version
)
$binPath = Join-Path $SolutionDir 'bin'
$objPath = Join-Path $SolutionDir 'obj'
$publishPath = Join-Path $ProjectDir $PublishDir
$msiPath = Join-Path $binPath "$Product-$RuntimeIdentifier-v$Version.msi"
$wxsPath = Join-Path $objPath 'package.wxs'
$zipPath = [System.IO.Path]::ChangeExtension($msiPath, '.zip')
$Version = $Version.Substring(0, $Version.LastIndexOf('.'))
if (!(Test-Path $binPath))
{
New-Item $binPath -ItemType Directory | Out-Null
}
if (!(Test-Path $objPath))
{
New-Item $objPath -ItemType Directory | Out-Null
}
$wxs = [xml]"<Wix xmlns=`"http://wixtoolset.org/schemas/v4/wxs`">
<Package Name=`"$Product`" Manufacturer=`"Richard Robertson`" Version=`"$Version`" UpgradeCode=`"34486a8a-8c84-4f38-8778-4f9a84a0c263`" Language=`"1033`">
<MajorUpgrade DowngradeErrorMessage=`"A newer version of [ProductName] is already installed.`" />
<MediaTemplate EmbedCab=`"yes`" />
<StandardDirectory Id=`"ProgramFiles6432Folder`">
<Directory Id=`"INSTALLFOLDER`" Name=`"!(bind.Property.ProductName)`" />
</StandardDirectory>
<StandardDirectory Id=`"ProgramMenuFolder`" />
<ComponentGroup Id=`"AppComponents`" Directory=`"INSTALLFOLDER`" />
<Feature Id=`"Main`">
<ComponentGroupRef Id=`"AppComponents`" />
</Feature>
</Package>
</Wix>"
$publishFiles = Get-ChildItem $publishPath
foreach ($file in $publishFiles)
{
$component = $wxs.CreateElement('Component', 'http://wixtoolset.org/schemas/v4/wxs')
$wxs['Wix']['Package']['ComponentGroup'].AppendChild($component) | Out-Null
$fileElement = $wxs.CreateElement('File', 'http://wixtoolset.org/schemas/v4/wxs')
$component.AppendChild($fileElement) | Out-Null
$fileElement.SetAttribute('Source', $file.FullName)
if ($file.Extension -eq '.exe' -and $file.BaseName -eq $AssemblyName)
{
$shortcut = $wxs.CreateElement('Shortcut', 'http://wixtoolset.org/schemas/v4/wxs')
$fileElement.AppendChild($shortcut) | Out-Null
$shortcut.SetAttribute('Name', $AssemblyName)
$shortcut.SetAttribute('Directory', 'ProgramMenuFolder')
}
}
$publishFiles | Compress-Archive -DestinationPath $zipPath -Force
$wxs.Save($wxsPath)
wix build -arch x64 -out $msiPath $wxsPath