Skip to content

Commit f57a729

Browse files
feat: add upgradeCode config option (#11039)
* feat: add `upgradeCode` config option * fix build on other platforms * Update crates/tauri-bundler/src/bundle/settings.rs [skip ci] * move to subcommand, use same product name fallback as the bundler --------- Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
1 parent 3f1a8a4 commit f57a729

File tree

14 files changed

+131
-8
lines changed

14 files changed

+131
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": "patch:feat"
3+
"@tauri-apps/cli": "patch:feat"
4+
---
5+
6+
Add `tauri inspect wix-upgrade-code` to print default Upgrade Code for your MSI installer derived from `productName`.

.changes/upgrade-code-option.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-utils": "patch:feat"
3+
"tauri-bundler": "patch:feat"
4+
---
5+
6+
Add `upgradeCode` in `wix` configuration to set an upgrade code for your MSI installer. This is recommended to be set if you plan to change your `productName`.

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri-bundler/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ sha2 = "0.10"
4343
zip = { version = "2.0", default-features = false, features = ["deflate"] }
4444
dunce = "1"
4545
url = "2"
46+
uuid = { version = "1", features = ["v4", "v5"] }
4647

4748
[target."cfg(target_os = \"windows\")".dependencies]
48-
uuid = { version = "1", features = ["v4", "v5"] }
4949
bitness = "0.4"
5050
windows-registry = "0.2.0"
5151
glob = "0.3"

crates/tauri-bundler/src/bundle/settings.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ impl Default for WixLanguage {
351351
/// Settings specific to the WiX implementation.
352352
#[derive(Clone, Debug, Default)]
353353
pub struct WixSettings {
354+
/// A GUID upgrade code for MSI installer. This code **_must stay the same across all of your updates_**,
355+
/// otherwise, Windows will treat your update as a different app and your users will have duplicate versions of your app.
356+
///
357+
/// By default, tauri generates this code by generating a Uuid v5 using the string `<productName>.exe.app.x64` in the DNS namespace.
358+
/// You can use Tauri's CLI to generate and print this code for you by running `tauri inspect wix-upgrade-code`.
359+
///
360+
/// It is recommended that you set this value in your tauri config file to avoid accidental changes in your upgrade code
361+
/// whenever you want to change your product name.
362+
pub upgrade_code: Option<uuid::Uuid>,
354363
/// The app languages to build. See <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>.
355364
pub language: WixLanguage,
356365
/// By default, the bundler uses an internal template.

crates/tauri-bundler/src/bundle/windows/msi/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,21 @@ pub fn build_wix_app_installer(
548548
.unwrap_or_else(|| bundle_id.split('.').nth(1).unwrap_or(bundle_id));
549549
data.insert("bundle_id", to_json(bundle_id));
550550
data.insert("manufacturer", to_json(manufacturer));
551-
let upgrade_code = Uuid::new_v5(
552-
&Uuid::NAMESPACE_DNS,
553-
format!("{}.exe.app.x64", &settings.product_name()).as_bytes(),
554-
)
555-
.to_string();
556551

557-
data.insert("upgrade_code", to_json(upgrade_code.as_str()));
552+
// NOTE: if this is ever changed, make sure to also update `tauri inspect wix-upgrade-code` subcommand
553+
let upgrade_code = settings
554+
.windows()
555+
.wix
556+
.as_ref()
557+
.and_then(|w| w.upgrade_code)
558+
.unwrap_or_else(|| {
559+
Uuid::new_v5(
560+
&Uuid::NAMESPACE_DNS,
561+
format!("{}.exe.app.x64", &settings.product_name()).as_bytes(),
562+
)
563+
});
564+
data.insert("upgrade_code", to_json(upgrade_code.to_string()));
565+
558566
let product_code = Uuid::new_v5(
559567
&Uuid::NAMESPACE_DNS,
560568
settings.bundle_identifier().as_bytes(),

crates/tauri-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ walkdir = "2"
111111
elf = "0.7"
112112
memchr = "2"
113113
tempfile = "3"
114+
uuid = { version = "1", features = ["v5"] }
114115

115116
[dev-dependencies]
116117
insta = "1"

crates/tauri-cli/config.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,14 @@
21702170
"description": "Configuration for the MSI bundle using WiX.\n\n See more: <https://tauri.app/v1/api/config#wixconfig>",
21712171
"type": "object",
21722172
"properties": {
2173+
"upgradeCode": {
2174+
"description": "A GUID upgrade code for MSI installer. This code **_must stay the same across all of your updates_**,\n otherwise, Windows will treat your update as a different app and your users will have duplicate versions of your app.\n\n By default, tauri generates this code by generating a Uuid v5 using the string `<productName>.exe.app.x64` in the DNS namespace.\n You can use Tauri's CLI to generate and print this code for you, run `tauri inspect wix-upgrade-code`.\n\n It is recommended that you set this value in your tauri config file to avoid accidental changes in your upgrade code\n whenever you want to change your product name.",
2175+
"type": [
2176+
"string",
2177+
"null"
2178+
],
2179+
"format": "uuid"
2180+
},
21732181
"language": {
21742182
"description": "The installer languages to build. See <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>.",
21752183
"default": "en-US",

crates/tauri-cli/src/helpers/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub type ConfigHandle = Arc<Mutex<Option<ConfigMetadata>>>;
6262

6363
pub fn wix_settings(config: WixConfig) -> tauri_bundler::WixSettings {
6464
tauri_bundler::WixSettings {
65+
upgrade_code: config.upgrade_code,
6566
language: tauri_bundler::WixLanguage(match config.language {
6667
WixLanguage::One(lang) => vec![(lang, Default::default())],
6768
WixLanguage::List(languages) => languages

crates/tauri-cli/src/inspect.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use anyhow::Result;
6+
use clap::{Parser, Subcommand};
7+
8+
use crate::interface::{AppInterface, AppSettings, Interface};
9+
10+
#[derive(Debug, Parser)]
11+
#[clap(about = "Manage or create permissions for your app or plugin")]
12+
pub struct Cli {
13+
#[clap(subcommand)]
14+
command: Commands,
15+
}
16+
17+
#[derive(Subcommand, Debug)]
18+
enum Commands {
19+
/// Print the default Upgrade Code used by MSI installer derived from productName.
20+
WixUpgradeCode,
21+
}
22+
23+
pub fn command(cli: Cli) -> Result<()> {
24+
match cli.command {
25+
Commands::WixUpgradeCode => wix_upgrade_code(),
26+
}
27+
}
28+
29+
// NOTE: if this is ever changed, make sure to also update Wix upgrade code generation in tauri-bundler
30+
fn wix_upgrade_code() -> Result<()> {
31+
crate::helpers::app_paths::resolve();
32+
33+
let target = tauri_utils::platform::Target::Windows;
34+
let config = crate::helpers::config::get(target, None)?;
35+
36+
let interface = AppInterface::new(config.lock().unwrap().as_ref().unwrap(), None)?;
37+
38+
let product_name = interface.app_settings().get_package_settings().product_name;
39+
40+
let upgrade_code = uuid::Uuid::new_v5(
41+
&uuid::Uuid::NAMESPACE_DNS,
42+
format!("{product_name}.exe.app.x64").as_bytes(),
43+
)
44+
.to_string();
45+
46+
log::info!("Default WiX Upgrade Code, derived from {product_name}: {upgrade_code}");
47+
if let Some(code) = config.lock().unwrap().as_ref().and_then(|c| {
48+
c.bundle
49+
.windows
50+
.wix
51+
.as_ref()
52+
.and_then(|wix| wix.upgrade_code)
53+
}) {
54+
log::info!("Application Upgrade Code override: {code}");
55+
}
56+
57+
Ok(())
58+
}

0 commit comments

Comments
 (0)