You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Tauri项目添加依赖DLL的Sidecar组件

解决Tauri Sidecar依赖DLL的打包问题

方案1:通过Tauri配置指定资源输出路径(推荐)

在tauri.conf.json中,除了配置Sidecar,还可以通过resources字段添加DLL,并调整资源输出配置让DLL和Sidecar exe处于同一目录:

  1. 找到tauri.bundle.resources数组,添加你的DLL文件路径,例如:
    "resources": ["./third-party/sidecar-deps/your-dll-file.dll"]
    
  2. 若是Tauri v2,可通过tauri.bundle.resourceDest指定资源输出到安装根目录(和Sidecar同位置):
    "resourceDest": "."
    
    若为Tauri v1,资源默认会放在resources子目录,此时需要配合build脚本将DLL拷贝到根目录。

方案2:利用Build钩子手动拷贝DLL

编写简单脚本在打包完成后自动将DLL复制到Sidecar所在目录,避免手动移动文件:

  • Windows环境可直接在package.json的scripts中添加拷贝命令:
    "scripts": {
      "tauri:build": "tauri build && copy ./third-party/sidecar-deps/your-dll-file.dll ./src-tauri/target/release/"
    }
    
  • 跨平台场景用Node.js脚本实现拷贝,比如创建copy-dll.js:
    const fs = require('fs');
    const path = require('path');
    
    const dllPath = path.resolve(__dirname, './third-party/sidecar-deps/your-dll-file.dll');
    const outputPath = path.resolve(__dirname, './src-tauri/target/release/');
    
    fs.copyFileSync(dllPath, path.join(outputPath, 'your-dll-file.dll'));
    
    再修改scripts:
    "scripts": {
      "tauri:build": "tauri build && node copy-dll.js"
    }
    

方案3:将Sidecar和DLL放在同一子目录

调整项目结构,把Sidecar exe和依赖DLL放在同一个子目录(比如./sidecars/),再在Tauri配置中指定路径:

  1. 项目结构示例:
    project-root/
    ├─ src-tauri/
    ├─ sidecars/
    │  ├─ your-sidecar.exe
    │  └─ your-dll-file.dll
    └─ ...
    
  2. 在tauri.conf.json中配置:
    "tauri": {
      "bundle": {
        "resources": ["./sidecars/*"]
      },
      "sidecars": ["./sidecars/your-sidecar.exe"]
    }
    
    打包后sidecars目录会完整复制到安装目录,Sidecar启动时能直接找到同目录的DLL,同时保持项目结构整洁。

注意事项

  • 确保DLL的架构(x64/x86)和Sidecar exe、Tauri主程序一致,避免运行时错误。
  • Tauri v1打包后资源默认在resources目录,若不拷贝到根目录,需确保Sidecar能正确加载该路径下的DLL。

内容的提问来源于stack exchange,提问作者Marshall Walker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 06:52:48