gpt4 book ai didi

c# - .NET Core 3.1 控制台应用程序将无法在 Windows 7 上运行

转载 作者:行者123 更新时间:2023-12-03 23:45:57 25 4
gpt4 key购买 nike

我创建了一个 .NET Core 3.1 AnyCpu使用带有最新补丁的 Visual Studio 2019 的控制台应用程序。它包含的唯一代码是样板文件 Console.WriteLine("Hello World!")它是用.我编译了它,它在我的 Windows 10 x64 机器上运行良好。
我复制了Debug文件夹转移到我的 32 位 Windows 7 盒子并尝试运行控制台应用程序。我收到以下消息。 (.Net Core 3.1 运行时安装在 Windows 7 机器上)。

The version of this file is not compatible with the version of Windowsyou're running. Check your computer's system information to see whetheryou need an x86 (32-bit) or x64 (64-bit) version of the program, and thencontact the software publisher.


但是,如果我使用 x86 编译控制台应用程序,那么它可以在 Windows 7 机器上正常运行。 VS2019 和 .NET Core 3/3.1 有 AnyCpu变了?我原以为为 AnyCpu 编译的代码在 32 位和 64 位下应该可以正常工作。

最佳答案

看起来 AnyCpu 在 .Net Core 3 中的工作方式发生了变化。在 .NET Framework 中,.exe 是一个托管 exe,因此使用 AnyCpu 它在运行时 JIT 到任何需要的 x86 或 x64 **。在使用 AnyCpu 的 .Net Core 中,.Exe 是一个普通的非托管 exe,针对 x86/x64 编译,具体取决于您的机器进行编译的架构是什么。但是,它创建的 dll 包含托管代码,可以使用 DotNet.exe 在 32 位计算机上运行。
解决方案不是在 32 位机器上编译,因为这只是在 32 位模式下启动 dll。解决方案实际上是不使用 .exe 并使用 DotNet.exe 的本地副本启动 dll。
** 来源:https://mihai-albert.com/2020/03/08/startup-sequence-of-a-dotnet-core-app/

关于c# - .NET Core 3.1 控制台应用程序将无法在 Windows 7 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62773887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com