为什么我的 .NET 6 WPF 项目无法在 Windows 7 上启动?

问题描述 投票:0回答:2

我知道 Windows 7 已经很旧了,但不幸的是很多人仍在使用它。考虑到这一点,我使用 .NET 6 制作了一个 WPF 应用程序。很明显,WPF 肯定受到 Windows 7 的支持,因为 WPF 于 2006 年发布,Windows 7 于 2009 年发布。当我在没有安装兼容的 .NET 运行时的计算机上运行该应用程序时,我会收到一个弹出窗口,要求我安装运行。所以我做了。到目前为止,一切都很好。然而现在,在 Windows 7 上,如果我启动该应用程序,它会立即终止并显示退出代码 9009,而在 Windows 10 计算机上它会正常启动。显然,Windows 7 仍然支持.NET 6,安装也很顺利。我想知道什么可能导致此问题以及如何进一步调试它。有没有办法在 Visual Studio 设置或我的 .csproj 文件中强制兼容 Windows 7?我试过 将

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
添加到我的 .csproj 中无济于事。使用 .NET 5 编译也没有帮助。从 Windows 11 运行具有 Windows 7 兼容性的应用程序工作正常,但在 Windows 7 虚拟机上失败。我还尝试使用
dotnet publish
进行编译,而不是仅仅在 Visual Studio 中构建,结果相同。

c# .net wpf windows-7
2个回答
3
投票

事实证明,事件查看器分别显示了一个有用的条目:

Message: Failed to load the dll from [C:\Program Files\dotnet\host\fxr\6.0.19\hostfxr.dll], HRESULT: 0x80070057
The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\6.0.19\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306

经过一番研究,我发现安装 KB4457144 可以解决问题,而且确实如此。


0
投票

我遇到了同样的问题,经过几天在各种 Windows 发行版(Windows 7 RTM、SP1、8.1...)上搜索和测试我的应用程序后,我认为我需要满足这些情况才能在任何 Windows 上运行我的应用程序:

  1. 我必须安装 Windows 7 的 SP1 更新(适用于 Windows 7 RTM (2009 发布版本): https://www.catalog.update.microsoft.com/Search.aspx?q=KB976932

  2. 然后我必须安装Windows 7的安全更新(如果未安装或更新,“我认为对于2016年之前的Windows版本”):Windows6.1-KB3063858

我测试了.Net5和.Net6。两者都适用于 Windows 7。

我还测试了一个独立的应用程序:它运行得很好。

但令我惊讶的是,当我使用 NetBeauty (nulastudio.NetBeauty) 将依赖项放在单独的 lib 文件夹而不是 Bin 文件夹中时,App 在新版本的 Windows 7 和 8.1 上运行(最后一个)更新) 但相同的文件未在第一个版本上运行,我还找不到原因。

© www.soinside.com 2019 - 2024. All rights reserved.