Repository: tauri-apps/tauri (language: rust)

Issue:
[bug] .msi bundle not working properly
### Describe the bug

During the windows bundle, I want to copy a .dll along the .exe.

I tested a lot of configurations when the .dll should be with the .exe, the .dll is completly missing from the installation directory. When the .dll is inside a directory it works without issue.

It works with the .nsis, but not with the .msi.


### Reproduction

 In tauri.conf.json I add this inside the bundle property: 
``` json
"resources": {
      "dll/opencv_world4110.dll": "opencv_world4110.dll"
}
```

or

``` json
"resources": [
      "opencv_world4110.dll"
]
```

Then, I run 
``` bash
yarn tauri build 
```

### Expected behavior

My dll should be with the .exe in Program Files.

### Full `tauri info` output

```text
[✔] Environment
    - OS: Windows 10.0.26100 x86_64 (X64)
    ✔ WebView2: 131.0.2903.112
    ✔ MSVC: Visual Studio Build Tools 2019
    ✔ rustc: 1.83.0 (90b35a623 2024-11-26)
    ✔ cargo: 1.83.0 (5ffbef321 2024-10-29)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 22.13.0
    - pnpm: 9.1.2
    - yarn: 1.22.22
    - npm: 10.9.2

[-] Packages
    - tauri 🦀: 2.2.1
    - tauri-build 🦀: 2.0.5
    - wry 🦀: 0.48.0
    - tao 🦀: 0.31.1
    - tauri-cli 🦀: 2.0.0-beta.22
    - @tauri-apps/api : 2.2.0
    - @tauri-apps/cli : 2.2.2

[-] Plugins
    - tauri-plugin-dialog 🦀: 2.2.0
    - @tauri-apps/plugin-dialog : not installed!
    - tauri-plugin-sql 🦀: 2.2.0
    - @tauri-apps/plugin-sql : not installed!
    - tauri-plugin-single-instance 🦀: 2.2.0
    - @tauri-apps/plugin-single-instance : not installed!
    - tauri-plugin-fs 🦀: 2.2.0
    - @tauri-apps/plugin-fs : not installed!

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite
```


### Stack trace

_No response_

### Additional context

_No response_


Discussion / hints:
For https://github.com/tauri-apps/tauri/pull/12324 i tested the msi and at least the WebView2Loader.dll was included correctly (only happens with the gnu toolchain). That doesn't use the resources feature though so maybe there's a timing issue or something.
I'll look into it :)

Fix patch:
diff --git a/.changes/fix-bundler-wix-dlls.md b/.changes/fix-bundler-wix-dlls.md
new file mode 100644
index 000000000000..bbe9063a130a
--- /dev/null
+++ b/.changes/fix-bundler-wix-dlls.md
@@ -0,0 +1,5 @@
+---
+tauri-bundler: 'patch:bug'
+---
+
+Fixed an issue that caused the .msi installer to not contain root resources when there were .dll files present in the target directory.
diff --git a/crates/tauri-bundler/src/bundle/windows/msi/mod.rs b/crates/tauri-bundler/src/bundle/windows/msi/mod.rs
index 6eef04fae0f1..c3d4cd6ac25d 100644
--- a/crates/tauri-bundler/src/bundle/windows/msi/mod.rs
+++ b/crates/tauri-bundler/src/bundle/windows/msi/mod.rs
@@ -1040,6 +1040,7 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
 
   let mut dlls = Vec::new();
 
+  // TODO: The bundler should not include all DLLs it finds. Instead it should only include WebView2Loader.dll if present and leave the rest to the resources config.
   let out_dir = settings.project_out_directory();
   for dll in glob::glob(
     &PathBuf::from(glob::Pattern::escape(&out_dir.to_string_lossy()))
@@ -1063,15 +1064,15 @@ fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
   }
 
   if !dlls.is_empty() {
-    resources.insert(
-      "".to_string(),
-      ResourceDirectory {
+    resources
+      .entry("".to_string())
+      .and_modify(|r| r.files.append(&mut dlls))
+      .or_insert(ResourceDirectory {
         path: "".to_string(),
         name: "".to_string(),
         directories: vec![],
         files: dlls,
-      },
-    );
+      });
   }
 
   Ok(resources)


Test patch: