Browse Source

fix(tauri-build): properly set executable version info on Windows (#4045)

Lucas Fernandes Nogueira 3 years ago
parent
commit
1ca2dd677d
3 changed files with 13 additions and 1 deletions
  1. 5 0
      .changes/fix-windows-exe-version.md
  2. 1 0
      core/tauri-build/Cargo.toml
  3. 7 1
      core/tauri-build/src/lib.rs

+ 5 - 0
.changes/fix-windows-exe-version.md

@@ -0,0 +1,5 @@
+---
+"tauri-build": patch
+---
+
+Properly set file version information for the Windows executable.

+ 1 - 0
core/tauri-build/Cargo.toml

@@ -26,6 +26,7 @@ serde_json = "1"
 
 [target."cfg(windows)".dependencies]
 winres = "0.1"
+semver = "1"
 
 [features]
 codegen = [ "tauri-codegen", "quote" ]

+ 7 - 1
core/tauri-build/src/lib.rs

@@ -256,7 +256,8 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
   #[cfg(windows)]
   {
     use anyhow::Context;
-    use winres::WindowsResource;
+    use semver::Version;
+    use winres::{VersionInfo, WindowsResource};
 
     let icon_path_string = attributes
       .windows_attributes
@@ -276,6 +277,11 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
         }
       }
       if let Some(version) = &config.package.version {
+        if let Ok(v) = Version::parse(version) {
+          let version = v.major << 48 | v.minor << 32 | v.patch << 16;
+          res.set_version_info(VersionInfo::FILEVERSION, version);
+          res.set_version_info(VersionInfo::PRODUCTVERSION, version);
+        }
         res.set("FileVersion", version);
         res.set("ProductVersion", version);
       }