从 Windows 10 编译 VS2017 在 Windows 7 上部署并且...未找到 DLL

Compile from Windows 10 VS2017 Deploy on Windows 7 and ... DLL not found

2.5 天,我尝试找到像

这样的错误的根源
Could not load file or assembly "mydll.dll" or one of its dependencies.
The specified module could not be found

该项目是一个 Windows 基于 C# 的应用程序。该 dll 是在项目内的 C++ 库中创建的。我在 Windows 10 64 位下使用 VS2017 Entreprise 进行编译,在 Windows 7 64 位下部署时遇到问题(在 Windwos 10 下部署效果很好......)。所有 .NET libs/exes/plugins 目标 .NET 4.5.2(安装在部署计算机上)。图书馆使用

Windows SDK Version: 8.1
Platform Toolset: Visual Studio 2017 (v141)

该项目制作了一个 msi 安装程序,我在部署计算机上成功安装了它。当然有dll。

于是我用process monitor观察了程序的执行情况。该 dll 似乎被加载了几次。 上次看到下面的

"10:31:13.7703319 AM","App.exe","1412","CloseFile","C:\Program Files (x86)\Vendor\Programm\ucrtbased.dll","SUCCESS",""
"10:31:13.7703575 AM","App.exe","1412","ReadFile","C:\Progra mFiles (x86)\Vendor\Programm\ucrtbased.dll","SUCCESS","Offset: 1,452,544, Length: 5,120, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal"
"10:31:13.7721639 AM","App.exe","1412","CreateFile","C:\Program Files (x86)\Vendor\Programm\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7722398 AM","App.exe","1412","CreateFile","C:\Windows\SysWOW64\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7723496 AM","App.exe","1412","CreateFile","C:\Windows\system\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7724133 AM","App.exe","1412","CreateFile","C:\Windows\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7725133 AM","App.exe","1412","CreateFile","C:\Windows\SysWOW64\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7725731 AM","App.exe","1412","CreateFile","C:\Windows\SysWOW64\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7726340 AM","App.exe","1412","CreateFile","C:\Windows\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7726991 AM","App.exe","1412","CreateFile","C:\Windows\SysWOW64\wbem\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7727622 AM","App.exe","1412","CreateFile","C:\Windows\SysWOW64\WindowsPowerShell\v1.0\api-ms-win-core-localization-l1-2-0.dll","NAME NOT FOUND","Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a"
"10:31:13.7729093 AM","App.exe","1412","CloseFile","C:\Program Files (x86)\Vendor\Programm\mydll.dll","SUCCESS",""

那个 api-ms-win-core-localization-l1-2-0.dll 确实被 dependency walker 和 [=18 一起列出了=]

API-MS-WIN-CORE-FILE-L1-2-0.DLL
API-MS-WIN-CORE-FILE-L2-1-0.DLL
API-MS-WIN-CORE-LOCALIZATION-L1-2-0.DLL
API-MS-WIN-CORE-PROCESSTHREADS-L1-1-1.DLL
API-MS-WIN-CORE-SYNCH-L1-2-0.DLL
API-MS-WIN-CORE-TIMEZONE-L1-1-0.DLL
API-MS-WIN-DOWNLEVEL-ADVAPI32-L1-1-0.DLL
API-MS-WIN-DOWNLEVEL-OLE32-L1-1-0.DLL
API-MS-WIN-DOWNLEVEL-SHLWAPI-L1-1-0.DLL
GPSVC.DLL
MSISO.DLL

Google告诉我所有这些都与这个问题无关... 在 linux 下 nm-Dldd...

下,现在只需 2.5 天即可完成您在 2.5 分钟内完成的工作

经过 3 天的努力,从 Windows 10 开始有效地瞄准 Windows 7,我分享了我的经验,并得出以下答案:
Microsoft 开发人员从未预见到这一点。 MS提供了一些hack,但无法实现可靠的开发链。

  1. 在您会遇到的其他问题中,看看这个 link ..(说真的,您必须手动卸载 Microsoft 软件包才能执行 Microsoft 更新?真的是 Microsoft 吗?)
  2. 截至 2018 年,没有有效的工具可以告诉您 Microsoft 世界中缺少什么动态库(基本上没有 ldd 的等价物)...甚至不要开始告诉我有关 DependecyWalker 或任何东西,它给出了太多的误报(>>100% 信噪比)并且已经过时了。

这与这里不值得一提的 1000 个其他 Microsoft 典型问题(程序包冲突等)一起,导致说这样做 可能 在理论上是可能的,但是在实践中不是。 (如果你在 Linux 下几分钟就能完成的事情需要花费数小时或数天,我认为这实际上不可行)

我给读者的建议是,如果你需要针对Win7,那就自己做一个Win7开发虚拟机。

当然,如果您的公司只能为您提供 VS2017 而不是 2015,就会出现问题。这种困境是 Microsoft 所熟知的,实际上这正是他们的目标。强迫您购买新产品,或者您的客户换用新产品 OS...

Richard Critten 的回答顺便说一句与这个问题无关