windows 如何在exe中捆绑依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5828073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to bundle dependencies in exe
提问by hoju
Often my exe's have dll dependencies that I package with an installer like nsisor inno. This makes sense for large programs but is overkill for small scripts.
通常,我的 exe 具有 dll 依赖项,我将这些依赖项与nsis或inno等安装程序打包在一起。这对于大型程序来说是有意义的,但对于小型脚本来说却是过度的。
Is there an alternative way to bundle dependencies, so that the user can just execute a single exe and not require a directory of dll's in the PATH?
是否有另一种方法来捆绑依赖项,以便用户可以只执行一个 exe 而不需要 PATH 中的 dll 目录?
EDIT
编辑
I am hoping for a solution that won't depend on the type of dll's, and will work for other kinds of dependencies too.
我希望有一个不依赖于 dll 类型的解决方案,并且也适用于其他类型的依赖项。
Here are some potential options:
以下是一些潜在的选择:
- http://www.adontec.com/index.htm?GO=/runtimepacker_e.htm
- http://boxedapp.com/
- http://www.filetransit.com/view.php?id=16640
- http://www.adontec.com/index.htm?GO=/runtimepacker_e.htm
- http://boxedapp.com/
- http://www.filetransit.com/view.php?id=16640
Does anyone have experience with a tool like this?
有没有人有使用这样的工具的经验?
采纳答案by selbie
Ok, you didn't like either of my other two ideas... so here goes...
好吧,你不喜欢我的其他两个想法中的任何一个......所以这里......
You ship and give your customers a "stub EXE". The stub EXE doesn't depend on anything else and just contains a ZIP file (or setup package or similar) as a resource in your stub EXE. The zip file embedded in the stub EXE just contains the actual program EXE and all its dependent DLLs. When the stub EXE runs, it just unpacks the ZIP file to a TEMP sub-directory and launches the application EXE.
您运送并为您的客户提供“存根 EXE”。存根 EXE 不依赖于任何其他东西,只包含一个 ZIP 文件(或安装包或类似文件)作为存根 EXE 中的资源。嵌入在存根 EXE 中的 zip 文件仅包含实际程序 EXE 及其所有相关 DLL。当存根 EXE 运行时,它只是将 ZIP 文件解压到 TEMP 子目录并启动应用程序 EXE。
You could optimize it such that if the app has already been installed in %TEMP%, then you skip the unpacking step and just launch the application EXE already present.
您可以优化它,如果应用程序已经安装在 %TEMP% 中,那么您可以跳过解包步骤,直接启动已经存在的应用程序 EXE。
Personally, I wouldn't go this route. Just give the user an installer if the EXE has dependencies. But you know your users and customers better than I do.
就我个人而言,我不会走这条路。如果 EXE 有依赖关系,只需给用户一个安装程序。但是您比我更了解您的用户和客户。
回答by Delan Azabani
You could statically link the executable.
您可以静态链接可执行文件。
回答by selbie
You didn't mention what the DLL dependencies are. Just straight up DLLs with a stub lib? Dynamically loaded via LoadLibrary? COM? Registration required? Is any of this .NET?
您没有提到 DLL 依赖项是什么。直接使用存根库直接生成 DLL?通过 LoadLibrary 动态加载?通讯?需要注册吗?这是 .NET 中的任何一个吗?
Several options to consider.
需要考虑的几个选项。
Put the all the required DLLs in the same directory as the EXE (so you don't have to muck with the PATH variable). Installation is just a "copy *.*" or just allowed to run from a file share. (YMMV if there is .NET code - as that has security restriction when run from a remote file share).
Statically link the EXE with the C-Runtime instead of the dynamic option (so you don't have to redist the MSVCRT on machines that don't already have it installed).
将所有必需的 DLL 与 EXE 放在同一目录中(这样您就不必与 PATH 变量混淆了)。安装只是“复制*.*”或仅允许从文件共享运行。(YMMV 如果有 .NET 代码 - 因为从远程文件共享运行时具有安全限制)。
将 EXE 与 C-Runtime 静态链接而不是动态选项(因此您不必在尚未安装 MSVCRT 的机器上重新发布它)。
I have some crazier ideas if the above 2 items don't suffice. Let me know.
如果以上 2 项还不够,我有一些更疯狂的想法。让我知道。
回答by pjwilliams
One alternative is to install the DLL's in the GAC.
一种替代方法是在 GAC 中安装 DLL。