C# 为什么在 Visual Studio 2012 中禁用了“首选 32 位”复选框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16546886/
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-10 01:18:24  来源:igfitidea点击:

Why is the checkbox 'Prefer 32-bit' disabled in Visual Studio 2012?

c#visual-studiovisual-studio-2012

提问by Dzyann

I came across a situation in which I would like to set the Prefer 32-bitto true. But in Visual Studio 2012, it is showing as disabled. And no matter what I do it doesn't get enabled.

我遇到了一种情况,我想将Prefer 32-bit 设置为 true。但在 Visual Studio 2012 中,它显示为已禁用。无论我做什么,它都不会被启用。

I read that Any CPUwith Prefer 32-bitis the default value for all new projects. So, should I assume that although it is disabled it is set to true? Then how can you set it to be just Any CPU?

我读到Any CPUwith Prefer 32-bit是所有新项目的默认值。那么,我是否应该假设虽然它被禁用但它被设置为 true?那你怎么能把它设置为Any CPU呢?

In What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11and in many other posts and questions here in Stack Overflow it says:

AnyCPU 的真正含义 As Of .NET 4.5 and Visual Studio 11以及 Stack Overflow 的许多其他帖子和问题中,它说:

overall, there are now five options for the /platform C# compiler switch: x86, Itanium, x64, anycpu, and anycpu 32bit preferred

总体而言,/platform C# 编译器开关现在有五个选项:x86、Itanium、x64、anycpu 和 anycpu 32bit 首选

What's more, I have some collegues that have mentioned to me that in the past that checkbox was enabled (maybe they are wrong?).

更重要的是,我有一些同事向我提到过去启用了复选框(也许他们错了?)。

Why is the Prefer 32-bitcheckbox disabled, and how can I enable it again?

为什么首选 32 位复选框被禁用,我该如何再次启用它?

My processor is 64-bit, and I have applied the Update2 to Visual Studio 2012.

我的处理器是 64 位的,并且我已将 Update2 应用到 Visual Studio 2012。

采纳答案by Matthew Watson

Assuming you've got an executable project, then if you change your target platform to .NET 4.5, it should become enabled.

假设您有一个可执行项目,那么如果您将目标平台更改为 .NET 4.5,它应该会被启用。

It's a .NET 4.5-only thing, and it's only enabled for executables.

它仅适用于 .NET 4.5,并且仅对可执行文件启用。

回答by Ron Deijkers

In case anybody encounters this for a .NET 4.5 executable in Visual Studio 2013 (and possibly Visual Studio 2012):

万一有人在 Visual Studio 2013(可能还有 Visual Studio 2012)中遇到 .NET 4.5 可执行文件:

We solved it by switching the project to .NET 4.0 and then back .NET 4.5 (on the Build tab of the project properties). This reenabled the checkbox "Prefer 32 bit" for AnyCPU.

我们通过将项目切换到 .NET 4.0 然后返回 .NET 4.5(在项目属性的 Build 选项卡上)解决了这个问题。这为 AnyCPU 重新启用了“首选 32 位”复选框。

回答by NJS

This setting may also be disabled if your project is a unit test project. It turns out the setting wasn't my issue anyway. I got tests running by changing the Visual Studio test runner to run tests as a 64-bit process.

如果您的项目是单元测试项目,也可能会禁用此设置。事实证明,无论如何设置都不是我的问题。我通过将 Visual Studio 测试运行器更改为 64 位进程来运行测试来运行测试。

In Visual Studio Community 2015, I found this in the Test menu:
Test > Test Settings > Default Processor Architecture > X64

在 Visual Studio Community 2015 中,我在 Test 菜单中找到了这个:
Test > Test Settings > Default Processor Architecture > X64

Here's more info from Microsoft:
https://msdn.microsoft.com/en-us/library/ee782531.aspx

以下是来自 Microsoft 的更多信息:https:
//msdn.microsoft.com/en-us/library/ee782531.aspx