Visual Studio:如何正确构建和指定 x64 和 x86 的配置和平台 [英] Visual Studio: How to properly build and specify the configurations and platforms for x64 and x86

查看:67
本文介绍了Visual Studio:如何正确构建和指定 x64 和 x86 的配置和平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用:带有所有最新更新的 Visual Studio 2012 Professional 和 Ultimate

Using: Visual Studio 2012 Professional and Ultimate with all latest updates

如何正确指定配置和平台以正确构建 x86 和 x64.

How do I properly specify the configuration and platform to properly build x86 and x64.

Visual Studio,当您第一次创建 Winforms 应用程序时,会为您提供两种配置,Debug 和 Release,其中 AnyCPU 定义为平台.

Visual Studio, when you first create a Winforms application gives you two configurations, Debug and Release, with AnyCPU defined as the platform.

如果你只针对一个平台,那么答案很简单,你去 Build |配置管理器并选择其中一个平台,然后转到项目属性的构建页面并选择相同的平台(x86 或 x64),瞧!你最终得到(比如你想要 x86)

If you just target one platform, then the answer is easy, you go to the Build | Configuration Manager and select one of the platforms and then go to the project properties' build page and select the same platform (x86 or x64) and voila! You wind up with (say you want x86)

/bin/x86/Debug
/bin/x86/Release

我有一个包含一个应用程序和多个依赖项项目(DLL 程序集)的解决方案.

I have a solution with one application and multiple dependency projects (DLL assemblies).

由于 VS 配置管理器在顶部有两个下拉列表,配置和平台,然后在项目级别有另一个配置和平台,我做了以下操作:

Since the VS Configuration Manager has two dropdown lists at the top, Configuration and Platform and then on the project level another configuration and platform, I did the following:

(在进一步输入之前,我认为整个设置很糟糕,但是...)

(Before typing further, I think the whole setup sucks, but...)

我使用最顶部的下拉列表和为平台选择的混合平台创建了两个新配置 Debug64 和 Release64.

I created two new configurations Debug64 and Release64 using the top most dropdown and selected Mixed Platforms for the platform.

我依次选择了四个主要解决方案配置中的每一个,然后将项目级配置和项目级平台设置为匹配,因此:

I selected each of the four main solution configurations in turn and then set the project level configuration and project level platform to match, so:

Debug64 === Debug64, x64
Release64 === Release64, x64
Debug === Debug, x86
Release === Release, x86

然后我进入项目属性(Alt + Enter)构建页面,忽略平台并依次选择每个配置,然后将目标处理器设置为匹配.我将输出更改为以下内容:

I then went into the project properties (Alt + Enter) build page, ignored the platform and selected each configuration in turn and then set the target processor to match. I changed the output to be the following:

Debug64: /bin/x64/Debug
Release64: /bin/x64/Release
Debug: /bin/x86/Debug
Release: /bin/x86/Release

默认情况下,Visual Studio 使用顶层平台设置文件夹和配置名称来设置输出的最后一部分.如果我保存并关闭项目属性,那么一切似乎都很好.我可以构建并最终使用正确的文件夹.

By default, Visual Studio uses the top platform to set the folder and the configuration name to set the last part of the output. If I save and close out of the project properties, then all seems fine. I can build, and wind up with the proper folders.

问题来了,当我在 Visual Studio 工具栏上切换解决方案配置时.默认情况下,项目属性构建页面恢复到它想要的状态,即,用于调试的/bin/x64/Debug64 和用于发布的类似内容.

The problem comes, when I switch solution configurations on the Visual Studio toolbar. The project properties build page reverts back to what it wants by default, namely, say, /bin/x64/Debug64 for both debugs and something similar for the release.

促使我写这个问题的原因是设计者很困惑,找不到合适的库.

What prompted me to write this issue is that the designer gets confused and cannot find the appropriate library.

我想从 Visual Studio 解决方案配置下拉列表中选择我想要的目标(调试 x64、发布 x64、调试 x86、发布 x86)并构建它.

I would like to select from the Visual Studio solution configuration dropdown my desired target (Debug x64, Release x64, Debug x86, Release x86) and have it build.

我该怎么做?我做错了什么?

How do I do that? What am I doing wrong?

仅创建两个解决方案配置(调试和发布)不起作用,因为没有解决方案平台下拉列表,然后针对所有子项目.在我看来,Visual Studio 有太多的配置部分和平台部分.也许我只是错过了一些东西.

Creating just two solution configurations, Debug and Release, does not work, because there is no solution platform dropdown, which then targets all sub-projects. Visual Studio has, it seems to me, way too many configurations sections and platform sections. Maybe I am just missing something.

推荐答案

对于后代,这里是答案.这听起来很明显,但对我来说不是,所以...

For posterity, here is the answer. It may sound obvious, but it was not to me, so...

注意:创建 Debug64 和 Release64 是让我付出代价的错误.我不仅必须删除解决方案中存在的 Debug64 和 Release64(在配置管理器中),而且我必须删除为每个项目自动生成的 Debug64 和 Release64(也在配置管理器中,只是在表格部分).这花了一段时间.

Notes: Creating Debug64 and Release64 were mistakes that cost me. I not only had to remove the Debug64 and Release64 present in the solutions (in Configuration Manager), but I had to delete the automatically generated Debug64 and Release64 for each of the projects (also in Configuration Manager, just in the table part). That took a while.

  1. 确保您拥有自动生成的调试和发布解决方案配置.

  1. Make sure that you have the automatically generated debug and release solution configurations.

在解决方案平台中添加 x86 和 x64.默认为任何 CPU.

In the solution platforms add in x86 and x64. The default is Any CPU.

从解决方案配置和平台下拉列表中选择(调试/发布和 x86/x64)的各种排列.确保项目匹配,它们应该匹配.

Select from the solution configuration and platform dropdowns the various permutations of (Debug/Release and x86/x64). Make sure the projects match, which they should.

进入每个项目(选择项目名称,然后 Alt+Enter).

Go into each project (select project name and then Alt+Enter).

在项目属性页面中,在解决方案下拉列表中选择调试/发布和 x86/x64 的各种排列.确保目标处理器设置正确(应该是,但我发现它们不是,可能是因为我以前的尝试).另外,设置输出目录.这应该没问题并且是自动的(/bin/x86/Debug 等).如果没有,请修复.

In the project properties page, select the various permutations of Debug/Release and x86/x64 in the solution dropdowns. Make sure the target processor is set correctly (it should be, but I found instances when they were not, probably because of my previous attempts). Also, set the output directory. That should be okay and automatic (/bin/x86/Debug, etc.). If not, fix.

微软在工具栏中没有解决方案平台下拉菜单,所以如果你想改变解决方案平台,那么你必须去Build |Configuration Manager 并选择合适的解决方案平台.您可以从 Build | 中选择解决方案配置.配置管理器(Visual Studio 将自动更新工具栏下拉列表中选定的解决方案配置)或只需在 Visual Studio 下拉列表中选择新的解决方案配置.

Microsoft does not have a solution platform dropdown in the toolbar, so if you want to change solution platforms, then you must go to the Build | Configuration Manager and select the appropriate solution platform. You can select the solution configuration either from the Build | Configuration Manager (Visual Studio will automatically update the selected solution configuration in the toolbar dropdown) or simply select the new solution configuration in the Visual Studio dropdown.

构建项目将负责其余的工作.

Building the project will take care of the rest.

构建说明1. Visual Studio 设计器需要 x86 版本的用户控件才能正确显示.这在开始时并不明显,但现在很明显.Visual Studio 安装到C:Program Files (x86)"文件夹而不是C:Program Files"文件夹,使 Visual Studio 成为 32 位应用程序,而不是 64 位应用程序,因此它能够使用" 设计器中只有 32 位版本.

Build Notes 1. The Visual Studio designer requires x86 versions of user controls in order to display properly. That was not obvious at the onset, but is now. Visual Studio installs to the "C:Program Files (x86)" folder and not the "C:Program Files" folder, making Visual Studio a 32-bit application, not a 64-bit one, hence its ability to "use" only 32-bit versions in the designer.

  1. 可能存在杂散的/bin/Debug 和/bin/release 文件夹,但它们不会被使用.

  1. There might be stray /bin/Debug and /bin/release folders, but they will not be used.

在不同的配置上构建相同的代码时,我仍然试图让 BuildVersionInc 不增加,但这是一个不同的问题.

I am still trying to get BuildVersionInc to not increment when building the same code through on different configurations, but that is a different issue.

这篇关于Visual Studio:如何正确构建和指定 x64 和 x86 的配置和平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆