我怎么才能让我的应用在64位计算机上以32位运行?
这段代码是用C#编写的。
右键点击您的项目,然后选择属性。
在属性中,选择构建选项卡。在平台目标下,选择 x86。
按下 Ctrl+Shift+S 保存所有文件,右键单击解决方案并选择 "清理" 来删除旧二进制文件。此后任何构建都应该是 32 位的。
命令行格式:
corflags application.exe /32BIT+
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");
}
如果你在Visual Studio中进入配置管理器,你可以将平台设置为x86或x64。
将项目设置为x86会防止文件在非x86平台上执行,例如ARM。自Visual Studio 11和.NET Framework 4.5以来,有一个名为 Any CPU 32-bit preferred
的新选项,这是默认选项。生成的代码将在任何平台上运行,但在64位平台上,它们将作为32位进程运行。