如何为 MSBuild 指定平台? [英] How do I specify the platform for MSBuild?

查看:33
本文介绍了如何为 MSBuild 指定平台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MSBuild 构建具有指定目标平台的解决方案(我需要二进制文件,x86 和 x64).我就是这样尝试的:

C:WINDOWSMicrosoft.NETFrameworkv3.5>MsBuild SolutionPathSolution.sln/t:Rebuild/p:Configuration=Release/p:Platform="x86"

但是,如果平台与任何 CPU"不同,则构建总是会失败.我做错了什么?

这是 MSBuild 打印的 while 输出:

<块引用>

C:WINDOWSMicrosoft.NETFrameworkv3.5>MsBuildSolutionPathSolution.sln/t:重建/p:配置=发布/p:Platform="x86" Microsoft (R) 构建引擎版本 3.5.30729.1 [微软.NET 框架,版本2.0.50727.3082] 版权所有 (C) Microsoft Corporation 2007.所有权利保留.

构建开始于 1.7.2010 8:28:10.项目SolutionPathSolution.sln"节点 0(重建目标 t(s)).解决方案路径解决方案.sln:错误MSB4126:指定的解决方案配置Release|x86"是无效的.请指定一个有效的解决方案配置使用配置和平台属性(例如 MSBuild.exe Solution.sln/p:配置=调试/p:Platform="Any CPU") 或离开那些属性空白以使用默认值解决方案配置.完成建筑项目SolutionPathSolution.sln"(重建目标)--失败.

构建失败.

SolutionPathSolution.sln"(重建目标)(1)->(ValidateSolutionConfiguration 目标)-> SolutionPathSolution.sln : 错误 MSB4126: 指定的解决方案配置Release|x86"是无效的.请指定一个有效的解决方案配置使用配置和平台属性(例如 MSBuild.exe e Solution.sln/p:配置=调试/p:Platform="Any CPU") 或离开那些属性空白以使用默认值解决方案配置.

0 个警告1 个错误

经过时间 00:00:00.03

如果我尝试使用 devenv 为 x86/x64 构建它,它可以完美运行,但是我试图在不安装所有必要版本的 Visual Studio 的情况下设置构建服务器.顺便说一句,如果有更好的免费工具(支持 .NET 框架 4),我很想听听.

解决方案

如果您想为 x86x64 构建您的解决方案,您的解决方案必须同时配置为平台.实际上你只是有一个Any CPU配置.

如何检查项目的可用配置

要检查给定项目的可用配置,请打开项目文件(例如 *.csproj)并查找具有正确 Condition 的 PropertyGroup.

如果你想在 x86Release 模式下构建,你的项目文件中必须有这样的内容:

...</属性组>

如何在 Visual Studio 中创建和编辑配置


(来源:
(来源:
(来源:msdn.com)

如何创建和编辑配置 (在 MSDN 上)

I am trying to use MSBuild to build a solution with a specified target platform (I need both binaries, x86 and x64). This is how I tried it:

C:WINDOWSMicrosoft.NETFrameworkv3.5>MsBuild SolutionPathSolution.sln /t:Rebuild /p:Configuration=Release /p:Platform="x86"

However the build always fails if the platform is different from "Any CPU". What am I doing wrong?

This is the while output MSBuild prints:

C:WINDOWSMicrosoft.NETFrameworkv3.5>MsBuild SolutionPathSolution.sln /t:Rebuild /p:Configuration=Release /p:Platform="x86" Microsoft (R) Build Engine Version 3.5.30729.1 [Microsoft .NET Framework, Version 2.0.50727.3082] Copyright (C) Microsoft Corporation 2007. All rights reserved.

Build started 1.7.2010 8:28:10. Project "SolutionPathSolution.sln" on node 0 (Rebuild targe t(s)). SolutionPathSolution.sln : error MSB4126: The specified sol ution configuration "Release|x86" is invalid. Please specify a valid solution c onfiguration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those prope rties blank to use the default solution configuration. Done Building Project "SolutionPathSolution.sln" (Rebuild t arget(s)) -- FAILED.

Build FAILED.

"SolutionPathSolution.sln" (Rebuild target) (1) -> (ValidateSolutionConfiguration target) -> SolutionPathSolution.sln : error MSB4126: The specified s olution configuration "Release|x86" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.ex e Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those pro perties blank to use the default solution configuration.

0 Warning(s)
1 Error(s)

Time Elapsed 00:00:00.03

If I try to build it for x86/x64 with devenv it works perfectly, however I am trying to set up a build server without installing all the necessary versions of Visual Studio. By the way, if there is a better free tool (that supports .NET framework 4) out there, I'd love to hear about it.

解决方案

If you want to build your solution for x86 and x64, your solution must be configured for both platforms. Actually you just have an Any CPU configuration.

How to check the available configuration for a project

To check the available configuration for a given project, open the project file (*.csproj for example) and look for a PropertyGroup with the right Condition.

If you want to build in Release mode for x86, you must have something like this in your project file:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  ...
</PropertyGroup>

How to create and edit the configuration in Visual Studio


(source: microsoft.com)


(source: msdn.com)


(source: msdn.com)

How to create and edit the configuration (on MSDN)

这篇关于如何为 MSBuild 指定平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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