Skip to content

Commit af93729

Browse files
fix: add missing file properties on Windows, closes #6676 (#6693)
Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.studio>
1 parent 262776d commit af93729

4 files changed

Lines changed: 51 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-build': 'patch'
3+
---
4+
5+
On Windows, set `LegalCopyright` and `FileDescription` file properties on the executable from `tauri.bundle.copyright` and `tauri.bundle.shortDescription`,

core/tauri-build/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,23 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
419419
));
420420
}
421421
}
422-
if let Some(version) = &config.package.version {
423-
if let Ok(v) = Version::parse(version) {
422+
if let Some(version_str) = &config.package.version {
423+
if let Ok(v) = Version::parse(version_str) {
424424
let version = v.major << 48 | v.minor << 32 | v.patch << 16;
425425
res.set_version_info(VersionInfo::FILEVERSION, version);
426426
res.set_version_info(VersionInfo::PRODUCTVERSION, version);
427427
}
428-
res.set("FileVersion", version);
429-
res.set("ProductVersion", version);
428+
res.set("FileVersion", version_str);
429+
res.set("ProductVersion", version_str);
430430
}
431431
if let Some(product_name) = &config.package.product_name {
432432
res.set("ProductName", product_name);
433-
res.set("FileDescription", product_name);
433+
}
434+
if let Some(short_description) = &config.tauri.bundle.short_description {
435+
res.set("FileDescription", short_description);
436+
}
437+
if let Some(copyright) = &config.tauri.bundle.copyright {
438+
res.set("LegalCopyright", copyright);
434439
}
435440
res.set_icon_with_id(&window_icon_path.display().to_string(), "32512");
436441
res.compile().with_context(|| {

tooling/bundler/src/bundle/windows/nsis.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ fn get_and_extract_nsis(nsis_toolset_path: &Path, _tauri_tools_path: &Path) -> c
121121
Ok(())
122122
}
123123

124+
fn add_build_number_if_needed(version_str: &str) -> anyhow::Result<String> {
125+
let version = semver::Version::parse(version_str).context("invalid app version")?;
126+
if !version.build.is_empty() {
127+
let build = version.build.parse::<u64>();
128+
if build.is_ok() {
129+
return Ok(format!(
130+
"{}.{}.{}.{}",
131+
version.major, version.minor, version.patch, version.build
132+
));
133+
} else {
134+
anyhow::bail!("optional build metadata in app version must be numeric-only");
135+
}
136+
}
137+
138+
Ok(format!(
139+
"{}.{}.{}.0",
140+
version.major, version.minor, version.patch,
141+
))
142+
}
124143
fn build_nsis_app_installer(
125144
settings: &Settings,
126145
_nsis_toolset_path: &Path,
@@ -164,7 +183,9 @@ fn build_nsis_app_installer(
164183
let mut data = BTreeMap::new();
165184

166185
let bundle_id = settings.bundle_identifier();
167-
let manufacturer = bundle_id.split('.').nth(1).unwrap_or(bundle_id);
186+
let manufacturer = settings
187+
.publisher()
188+
.unwrap_or_else(|| bundle_id.split('.').nth(1).unwrap_or(bundle_id));
168189

169190
#[cfg(not(target_os = "windows"))]
170191
{
@@ -177,10 +198,15 @@ fn build_nsis_app_installer(
177198
data.insert("bundle_id", to_json(bundle_id));
178199
data.insert("manufacturer", to_json(manufacturer));
179200
data.insert("product_name", to_json(settings.product_name()));
201+
data.insert("short_description", to_json(settings.short_description()));
180202
data.insert("copyright", to_json(settings.copyright_string()));
181203

182204
let version = settings.version_string();
183205
data.insert("version", to_json(version));
206+
data.insert(
207+
"version_with_build",
208+
to_json(add_build_number_if_needed(version)?),
209+
);
184210

185211
data.insert(
186212
"allow_downgrades",

tooling/bundler/src/bundle/windows/templates/installer.nsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Var ReinstallPageCheck
99
!define MANUFACTURER "{{manufacturer}}"
1010
!define PRODUCTNAME "{{product_name}}"
1111
!define VERSION "{{version}}"
12+
!define VERSIONWITHBUILD "{{version_with_build}}"
13+
!define SHORTDESCRIPTION "{{short_description}}"
1214
!define INSTALLMODE "{{install_mode}}"
1315
!define LICENSE "{{license}}"
1416
!define INSTALLERICON "{{installer_icon}}"
@@ -35,6 +37,13 @@ OutFile "${OUTFILE}"
3537
Unicode true
3638
SetCompressor /SOLID lzma
3739

40+
VIProductVersion "${VERSIONWITHBUILD}"
41+
VIAddVersionKey "ProductName" "${PRODUCTNAME}"
42+
VIAddVersionKey "FileDescription" "${SHORTDESCRIPTION}"
43+
VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
44+
VIAddVersionKey "FileVersion" "${VERSION}"
45+
VIAddVersionKey "ProductVersion" "${VERSION}"
46+
3847
!if "${PLUGINSPATH}" != ""
3948
!addplugindir "${PLUGINSPATH}"
4049
!endif

0 commit comments

Comments
 (0)