Windows 7、Windows 8.1 和 Windows 10 之间的通用 .Net 框架

Common .Net Framework between Windows 7, Windows 8.1 and Windows 10

我正在开发 C# Windows 表单应用程序。它是一个“Hello World”应用程序,不需要任何特殊的库,因此我不会强制使用任何特殊的 .Net Framework 版本。但对我来说最重要的是 运行 在所有 Windows 版本上安装应用程序,而无需安装或激活 .Net Framework。我想在 Windows 10、Windows 8.1 和 Windows 7 上 运行 此应用程序。 这些 Windows 上是否有任何常见的预装 .Net 框架版本?例如,.Net Framework 4.6 肯定预装在 Windows 10 上,但没有预装在 Windows 7 上。或者 .Net Framework 3.5 预装在 Windows 7 上,但没有预装在 Windows 上10 并且我的应用程序使用 .Net Framework 4.5

据我所知,您有两个选择。两者都有问题。

选项 1

This article 声明 .NET Framework 4.5 和更新版本向后兼容所有以前的版本,但有一个问题:

In practice, this compatibility can be broken by seemingly inconsequential changes in the .NET Framework and changes in programming techniques. For example, performance improvements in the .NET Framework 4.5 can expose a race condition that did not occur on earlier versions. Similarly, using a hard-coded path to .NET Framework assemblies, performing an equality comparison with a particular version of the .NET Framework, and getting the value of a private field by using reflection are not backward-compatible practices. In addition, each version of the .NET Framework includes bug fixes and security-related changes that can affect the compatibility of some apps and components.

乱七八糟的东西。

如果您走这条路,我建议您在要部署到的 Windows 的所有(主要 - 7、8、8.1、10)版本的全新安装上测试您的应用程序。您必须为每个版本执行此操作,并确保您手动测试所有功能。如果您不只是尝试 Hello World 应用程序,我不会推荐此路线。

选项 2

Windows Forms 自版本 3.0 以来已移植到 .NET Core,但是 Windows Forms 设计器不是 fully implemented yet.

使用 .NET Core 3.x 您可以部署一个自包含的应用程序 as described here,它将 运行 在 Windows 的所有版本上 Windows。