在 Visual C# 2008 Express Edition 中设置 32 位 x86 构建目标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1381968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 15:53:28  来源:igfitidea点击:

Setting 32-bit x86 build target in Visual C# 2008 Express Edition?

c#visual-studio-2008com32-bit

提问by John Douthat

I'm building a C# application that loads a 32-bit COM dll. The compiled application runs fine on 32-bit Windows but barfs on 64 bit Windows because it can't load the 32-bit COM. Is there a way to set a 32-bit build target in VC# 2008 Express Edition?

我正在构建一个加载 32 位 COM dll 的 C# 应用程序。编译后的应用程序在 32 位 Windows 上运行良好,但在 64 位 Windows 上运行失败,因为它无法加载 32 位 COM。有没有办法在 VC# 2008 Express Edition 中设置 32 位构建目标?

Alternatively, is there a way to force a .NET application compiled to the AnyCPUbuild target to run in 32-bit mode on 64-bit Windows?

或者,有没有办法强制编译到AnyCPU构建目标的 .NET 应用程序在 64 位 Windows 上以 32 位模式运行?

采纳答案by adrianbanks

You cannot explicitly set it to 32-bit in the UI in VS Express, but apparently (I only have the Professional version at hand) it can be done using a bit of setting up. Thisforum post has details on how to do it.

您无法在 VS Express 的 UI 中将其明确设置为 32 位,但显然(我手头只有专业版)可以通过一些设置来完成。论坛帖子详细介绍了如何操作。

What you can also do is to use the CorFlagstool that comes with the .Net Framework SDKto set the compiled output to run as 32-bit. To set the 32-bit flag using CorFlags, run this from the command line:

您还可以使用.Net Framework SDK附带的CorFlags工具将编译后的输出设置为 32 位运行。要使用 CorFlags 设置 32 位标志,请从命令行运行:

CorFlags.exe /32BIT+ yourapp.exe

This will set a flag in the header of your exe to signal to .Net that it should be run as 32-bit.

这将在您的 exe 头文件中设置一个标志,以向 .Net 发出信号,表明它应该以 32 位运行。

回答by John Douthat

For posterity, here is the forum post adrian linked to:

对于后代,这是阿德里安链接到的论坛帖子:

In VC# Express, this property is missing, but you can still create an x86 configuration if you know where to look.

It looks like a long list of steps, but once you know where these things are it's a lot easier. Anyone who only has VC# Express will probably find this useful. Once you know about Configuration Manager, it'll be much more intuitive the next time.

  1. In VC# Express 2005, go to Tools -> Options.
  2. In the bottom-left corner of the Options dialog, check the box that says, "Show all settings".
  3. In the tree-view on the left hand side, select "Projects and Solutions".
  4. In the options on the right, check the box that says, "Show advanced build configuraions."
  5. Click OK.
  6. Go to Build -> Configuration Manager...
  7. In the Platform column next to your project, click the combobox and select "".
  8. In the "New platform" setting, choose "x86".
  9. Click OK.
  10. Click Close.

There, now you have an x86 configuration! Easy as pie! :-)

I also recommend using Configuration Manager to delete the Any CPU platform. You really don't want that if you ever have depedencies on 32-bit native DLLs (even indirect dependencies).

在 VC# Express 中,此属性缺失,但如果您知道在哪里查看,您仍然可以创建 x86 配置。

它看起来像一长串步骤,但一旦你知道这些东西在哪里,就容易多了。任何只有 VC# Express 的人可能会发现这很有用。一旦您了解了 Configuration Manager,下次它就会更加直观。

  1. 在 VC# Express 2005 中,转到工具 -> 选项。
  2. 在“选项”对话框的左下角,选中“显示所有设置”框。
  3. 在左侧的树视图中,选择“项目和解决方案”。
  4. 在右侧的选项中,选中“显示高级构建配置”框。
  5. 单击确定。
  6. 转到构建 -> 配置管理器...
  7. 在项目旁边的平台列中,单击组合框并选择“”。
  8. 在“新平台”设置中,选择“x86”。
  9. 单击确定。
  10. 单击关闭。

好了,现在您有了 x86 配置!非常简单!:-)

我还建议使用 Configuration Manager 删除 Any CPU 平台。如果您曾经依赖 32 位本机 DLL(甚至是间接依赖关系),那么您真的不希望出现这种情况。