【发布时间】:2020-07-20 19:19:03
【问题描述】:
我有一个使用 Visual Studio 2015 构建的 Windows x86 32 位桌面应用程序,该应用程序使用 C 和 C++ 编写,并使用 MFC 框架作为用户界面。对于安装程序,我使用带有 NSIS 脚本的 NSIS 编译器来生成用于安装应用程序的安装 .exe,该应用程序由构建创建的大约 10 个不同的组件、.exe 和 .dll 组成。
我的桌面应用程序是一个销售点应用程序,可在 32 位或 64 位版本的 POSReady 7 (Windows 7) 以及英特尔 x86/x64 兼容的 Windows 10 和 Windows 10 IoT Enterprise(非 Windows IoT Core)下运行CPU。
当我从 Visual Studio 2005 更改为 Visual Studio 2015 时,我对安装可执行文件的更大尺寸感到震惊,从大约 8 MB 的大小到 16 MB 的大小。大小差异似乎是由于我包含在桌面应用程序安装程序中的 Visual Studio 2015 C++ Redistributable。
NSIS 脚本有以下几行:
# The location of the Visual Studio 2005 C++ Runtime Redistributable depends on the version of
# Windows being used to build the application. Beginning with Windows 7 there are now two different
# folder hierarchies for installed programs.
File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\1033\vcredist_x86.exe"
ExecWait '"$INSTDIR\vcredist_x86.exe" /q:a /c:"msiexec /i vcredist.msi /qb!"' #dialog with no cancel
当我使用 Visual Studio 2015 编译桌面应用程序并运行带有注释掉的 File 指令的 NSIS 脚本时,生成的安装程序的大小为 2,220 KB。当我取消注释包含 vcredist_x86.exe 的 File 指令时,生成的安装程序的大小为 16,140 KB。
查看文件夹 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\1033 我看到三个不同的可再发行组件:vcredist_arm.exe 大小 2,639 KB、vcredist_x64.exe 大小 14,957 KB 和 vcredist_x86.exe 大小 14,130 KB。
是否有其他小于 14 MB 的 Visual Studio 2015 可再发行组件?
或者我可以使用其他方法来提供vcredist_x86.exe,而我不需要将它包含在我的应用程序安装程序中?一种不同的方法需要像当前解决方案一样自动安装应用程序组件,然后启动 Visual Studio 2015 可再发行安装程序。
备注
-
这篇文章的答案是将特定的 Visual Studio DLL 包含到安装程序的组件列表中。 How to avoid Visual C++ Redistributable LARGE file installing?
由于版权问题,这似乎不是一个可行的替代方案。
-
这里是指向 Microsoft 文档 Redistributing Visual C++ Files 和 Determining Which DLLS to Redistribute 的链接,其中包括使用 Redistributing Components By Using Merge Modules 中讨论的合并模块的替代方法。但是合并模块上的页面说:
我们建议您不要使用合并模块,除非您没有 为您的应用程序提供服务,并且您不再依赖更多 比一个版本的 DLL。合并不同版本的模块 同一个 DLL 不能包含在一个安装程序中,并且合并模块 使独立于您的应用程序的 DLL 服务变得困难。 相反,我们建议您安装 Visual C++ Redistributable 包。
【问题讨论】:
-
大多数人不需要它,因此您可以检测它是否已安装并在未安装时下载它,而不是将其包含在安装程序中
-
@AlanBirtles 我的应用程序是一个销售点应用程序,可以与 POSReady 7 以及 Windows 10 和 Windows 10 IoT Enterprise 一起使用。那些已经安装了 Visual Studio 2015 运行时?
-
我认为是 Windows 10
-
Win10 肯定可以,但要小心——安装的版本必须至少与您链接的确切运行时版本一样新(我发现 VS2019 有破坏 ABI 的坏习惯与点版本的兼容性——CRT 保持向后兼容,但链接到较新 CRT 的 .exe/.dll 不会与较旧 CRT 一起运行。
-
如果可以假设安装时可以访问互联网,如果安装的版本不够新,您可以在线安装
https://aka.ms/vs/16/release/vc_redist.x86.exe。可以在HKLM\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\X86\Version处查看版本(如果您的安装程序是 32 位 .exe,则没有 WOW 位)
标签: c++ visual-studio-2015 nsis vcredist