Skip to content

Commit a9ec90d

Browse files
authored
fix(msi): fix broken shortcut icon when using msi target, adding msi option iconId (#6247)
1 parent 8bd1f3e commit a9ec90d

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

.changeset/tiny-dolls-smoke.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
fix (msi): broken shortcut icon for desktop and startup entry (#5965)

packages/app-builder-lib/src/options/MsiOptions.ts

+5
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ export interface MsiOptions extends CommonWindowsInstallerConfiguration, TargetS
2323
* Any additional arguments to be passed to the WiX installer compiler, such as `["-ext", "WixUtilExtension"]`
2424
*/
2525
readonly additionalWixArgs?: Array<string> | null
26+
27+
/**
28+
* The [shortcut iconId](https://wixtoolset.org/documentation/manual/v4/reference/wxs/shortcut/). Optional, by default generated using app file name.
29+
*/
30+
readonly iconId?: string
2631
}

packages/app-builder-lib/src/targets/MsiTarget.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ export default class MsiTarget extends Target {
156156
const compression = this.packager.compression
157157
const options = this.options
158158
const iconPath = await this.packager.getIconPath()
159+
const iconId = `${appInfo.productFilename}Icon.exe`.replace(/\s/g, "")
159160
return (await projectTemplate.value)({
160161
...commonOptions,
161162
isCreateDesktopShortcut: commonOptions.isCreateDesktopShortcut !== DesktopShortcutCreationPolicy.NEVER,
162163
isRunAfterFinish: options.runAfterFinish !== false,
163164
iconPath: iconPath == null ? null : this.vm.toVmFile(iconPath),
165+
iconId: iconId,
164166
compressionLevel: compression === "store" ? "none" : "high",
165167
version: appInfo.getVersionInWeirdWindowsForm(),
166168
productName: appInfo.productName,
@@ -221,8 +223,9 @@ export default class MsiTarget extends Target {
221223
if (isMainExecutable && (isCreateDesktopShortcut || commonOptions.isCreateStartMenuShortcut)) {
222224
result += `>\n`
223225
const shortcutName = commonOptions.shortcutName
226+
const iconId = `${appInfo.productFilename}Icon.exe`.replace(/\s/g, "")
224227
if (isCreateDesktopShortcut) {
225-
result += `${fileSpace} <Shortcut Id="desktopShortcut" Directory="DesktopFolder" Name="${shortcutName}" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" Icon="icon.ico"/>\n`
228+
result += `${fileSpace} <Shortcut Id="desktopShortcut" Directory="DesktopFolder" Name="${shortcutName}" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" Icon="${iconId}"/>\n`
226229
}
227230

228231
const hasMenuCategory = commonOptions.menuCategory != null
@@ -231,7 +234,7 @@ export default class MsiTarget extends Target {
231234
if (hasMenuCategory) {
232235
dirs.push(`<Directory Id="${startMenuShortcutDirectoryId}" Name="ProgramMenuFolder:\\${commonOptions.menuCategory}\\"/>`)
233236
}
234-
result += `${fileSpace} <Shortcut Id="startMenuShortcut" Directory="${startMenuShortcutDirectoryId}" Name="${shortcutName}" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" Icon="icon.ico">\n`
237+
result += `${fileSpace} <Shortcut Id="startMenuShortcut" Directory="${startMenuShortcutDirectoryId}" Name="${shortcutName}" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" Icon="${iconId}">\n`
235238
result += `${fileSpace} <ShortcutProperty Key="System.AppUserModel.ID" Value="${this.packager.appInfo.id}"/>\n`
236239
result += `${fileSpace} </Shortcut>\n`
237240
}

packages/app-builder-lib/templates/msi/template.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
<Property Id="WixAppFolder" Value="WixPerUserFolder"/>
2121

2222
{{ if (iconPath) { }}
23-
<Icon Id="icon.ico" SourceFile="${iconPath}"/>
24-
<Property Id="ARPPRODUCTICON" Value="icon.ico"/>
23+
<Icon Id="${iconId}" SourceFile="${iconPath}"/>
24+
<Property Id="ARPPRODUCTICON" Value="${iconId}"/>
2525
{{ } -}}
2626

2727
{{ if (isAssisted || isRunAfterFinish) { }}

0 commit comments

Comments
 (0)