Skip to content

Commit 6f4b7a6

Browse files
committed
fix a bug with executables not in the root of
1 parent 4e2cbfb commit 6f4b7a6

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ To use this script you need the following tools installed on your machine:
1818
|Path|Yes|Null|The folder to create the MSI from|
1919
|Product|Yes|Null|The name to give the product. Used for Program Files folder, Desktop/Start Menu shortcut & others.|
2020
|Version|Yes|Null|The Version to report to AD etc...|
21-
|Executable|Yes|Null|The name of the exe inside `Path`.|
21+
|Executable|Yes|Null|The name of the exe inside `Path`. e.g. `App.exe` or `bin\app.exe`|
2222
|UpgradeGUID|No|Generated at Runtime|Supply the UpgradeGUID that was outputted when you generated the first version of the MSI.|
2323
|Manufacturer|No|Ed-IT Solutions MSI Creator|The manufacturer to set.|
2424
|Contact|No|System Administrator|Who should the user contact for help.|

create-msi-installer-from-folder.ps1

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,67 @@ step -message "Creating Installer.wixproj"
5050

5151
[xml]$installer = Get-Content "$PSScriptRoot\source\installer.wixproj"
5252

53+
Write-Host "Setting project information."
54+
5355
$installer.Project.PropertyGroup[0].OutputName = "$Product ($Version)"
5456
$installer.Project.PropertyGroup[0].ProjectGuid = "$ProjectGUID"
5557
$installer.Project.PropertyGroup[0].ProductVersion = $Version
5658
$installer.Project.PropertyGroup[1].DefineConstants = "Debug;HarvestPath=$Path;ProductVersion=$Version"
5759
$installer.Project.PropertyGroup[2].DefineConstants = "HarvestPath=$Path;ProductVersion=$Version"
5860
$installer.Project.Target[0].HeatDirectory.Directory = $Path
5961

62+
Write-Host "Saving to .\build"
63+
6064
$installer.Save("$PSScriptRoot\build\installer.wixproj")
6165

6266
step -message "Creating Product.wxs"
6367

6468
$productwxs = New-Object xml
6569
$productwxs.Load("$PSScriptRoot\source\product.wxs")
6670

71+
Write-Host "Setting product information."
72+
6773
$productwxs.Wix.Product.Name = $Product
6874
$productwxs.Wix.Product.Version = $Version
6975
$productwxs.Wix.Product.Manufacturer = $Manufacturer
7076
$productwxs.Wix.Product.UpgradeCode = $UpgradeGUID
7177

78+
Write-Host "Creating directories."
79+
7280
$productwxs.Wix.Product.Directory.Directory[0].Directory.Name = $Product
73-
$productwxs.Wix.Product.Directory.Directory[0].Directory.Component.File.Source = "$Path\$Executable"
81+
82+
$installDir = $productwxs.Wix.Product.Directory.Directory[0].Directory
83+
$installDir.Component.File.Source = "$Path\$Executable"
84+
85+
$dirs = $Executable.split('\')
86+
$i = 1
87+
88+
forEach($dir in $dirs){
89+
if($dir -notmatch '\.exe$'){
90+
$exeDir = $installDir.Clone()
91+
92+
$component = $installDir.Component
93+
$installDir.RemoveChild($component) | Out-Null
94+
95+
$exeDir.Id = "EXEDIR_$i"
96+
$exeDir.Name = $dir
97+
$installDir.appendChild($exeDir) | Out-Null
98+
$installDir = $exeDir
99+
$i = $i + 1
100+
}
101+
}
102+
103+
104+
105+
Write-Host "Creating start menu shortcut."
106+
74107
$productwxs.Wix.Product.Directory.Directory[1].Component.Shortcut.Name = $Product
75108
$productwxs.Wix.Product.Directory.Directory[1].Component.Shortcut.Description = $Product
76109
$productwxs.Wix.Product.Directory.Directory[1].Component.Shortcut.Target = "[INSTALLDIR]$Executable"
77110
$productwxs.Wix.Product.Directory.Directory[1].Component.RegistryValue.Key = "Software\$Product"
78111

79112
if($Desktop){
80-
Write-Host "Adding desktop shortcut"
113+
Write-Host "Creating desktop shortcut"
81114

82115
$desktopDirectory = $productwxs.Wix.Product.Directory.Directory[1].Clone()
83116
$desktopDirectory.Component.Shortcut.Id = "DesktopShortcut_001"
@@ -94,6 +127,8 @@ $productwxs.Wix.Product.Icon.SourceFile = "$Path\$Executable"
94127

95128
$productwxs.Wix.Product.Feature.Title = $Product
96129

130+
Write-Host "Setting contact information."
131+
97132
$productwxs.Wix.Product.Property[0].Value = $Contact
98133
$productwxs.Wix.Product.Property[1].Value = $HelpLink
99134
$productwxs.Wix.Product.Property[3].Value = $AboutLink
@@ -115,13 +150,17 @@ if($FileType){
115150
$productwxs.Wix.Product.Directory.Directory[0].Directory.Component.appendChild($appendable.ProgId) | Out-Null
116151
}
117152

153+
Write-Host "Saving to .\build"
154+
118155
$productwxs.Save("$PSScriptRoot\build\product.wxs")
119156

120157
step -message "Create Transform"
121158

122159
[xml]$transform = Get-Content "$PSScriptRoot\source\transform.xslt"
123160

124-
$transform.stylesheet.key.match = "wix:Component[contains(wix:File/@Source, '$Executable')]"
161+
$exe = Split-Path -Path "$Path\$Executable" -Leaf -Resolve
162+
163+
$transform.stylesheet.key.match = "wix:Component[contains(wix:File/@Source, '$exe')]"
125164

126165
$transform.Save("$PSScriptRoot\build\transform.xslt")
127166

source/installer.wixproj

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,6 @@
4646
<HintPath>$(WixExtDir)\WixUtilExtension.dll</HintPath>
4747
<Name>WixUtilExtension</Name>
4848
</WixExtension>
49-
<!--
50-
<WixExtension Include="WixFirewallExtension">
51-
<HintPath>$(WixExtDir)\WixFirewallExtension.dll</HintPath>
52-
<Name>WixFirewallExtension</Name>
53-
</WixExtension>
54-
<WixExtension Include="WixIIsExtension">
55-
<HintPath>$(WixExtDir)\WixIIsExtension.dll</HintPath>
56-
<Name>WixIIsExtension</Name>
57-
</WixExtension>
58-
<WixExtension Include="WixNetFxExtension">
59-
<HintPath>$(WixExtDir)\WixNetFxExtension.dll</HintPath>
60-
<Name>WixNetFxExtension</Name>
61-
</WixExtension>
62-
-->
6349
</ItemGroup>
6450

6551
<ItemGroup>

0 commit comments

Comments
 (0)