如何强制我的应用程序在64位计算机上以32位运行?
代码是用C#编写的。
答案 0 :(得分:22)
右键单击您的项目,然后选择属性。
在属性中,选择构建选项卡。在平台目标下,选择x86。
按Ctrl + Shift + S保存所有文件,右键单击解决方案并选择“清除”以删除旧的二进制文件。之后的任何构建都应该是32位
答案 1 :(得分:10)
命令行表单:
corflags application.exe /32BIT+
答案 2 :(得分:7)
由于ClickOnce限制,当我们无法将现有代码从任何CPU 更改为 x86 时,我就是这样做的:
创建一个32位(必须在项目属性下检查x86)'启动器'应用程序(Windows应用程序但不是表单):
static void Main(string[] args)
{
// Load the assembly
string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string assemblyName = Path.Combine(directory, "YourAnyCPUApplication.exe");
Assembly assembly = Assembly.LoadFile(assemblyName);
assembly.EntryPoint.Invoke(null, null);
}
将以下代码添加到 Any CPU 项目中的Main方法:
if (IntPtr.Size == 4)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// etc...
}
else
{
// Launch application in 32-bit mode
System.Diagnostics.Process.Start(Path.GetDirectoryName(Application.ExecutablePath) + @"\Your32BitApplicationLauncher.exe");
}
我希望这会有所帮助:-)
答案 3 :(得分:5)
如果转到Visual Studio中的Configuration Manager,则可以将平台设置为x86或x64。
答案 4 :(得分:1)
假设这是一个Winforms,控制台应用程序或Windows服务,您必须为x86而不是任何CPU构建exe。它位于Configuration Manager中。
答案 5 :(得分:0)
Visual Studio 11和.NET framwork 4.5或更高版本有Any CPU 32-bit preferred
选项,这是默认设置
生成的代码将在任何平台上运行,但在64位平台上,它们作为32位进程运行