我无法在Visual Studio中同时构建一个项目的多个配置,但是可以使用MSBuild [英] I can't build multiple configuration(s) of a project at the same time in Visual Studio, but I can with MSBuild

查看:110
本文介绍了我无法在Visual Studio中同时构建一个项目的多个配置,但是可以使用MSBuild的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个项目中同时构建两个配置.假设我要构建发行版,但甚至要构建调试版(事实并非如此).

I want to build two configurations at the same time of a project. Let's say that when I want to build the release version, but I want to build even the debug version (the opposite isn't true).

Starting with Use a single Visual Studio solution to build both x86 and x64 at the same time? I've tried adding to the .csproj:

<Target Name="AfterBuild">
    <MSBuild Condition=" '$(Configuration)' == 'Release' " Projects="$(MSBuildProjectFile)" Properties="Configuration=Debug" RunEachTargetSeparately="true" />
</Target>

如果我尝试通过MSBuild构建项目,

And if I try to build the project through MSBuild,

MSBuild ConsoleApplication64.csproj /p:Configuration=Release /p:Platform=x86

它正常工作.两种配置正确构建,一切都很好.

it works correctly. The two configurations are built correctly and everything is good.

问题是,如果我尝试使用Visual Studio构建它:发行版本正确构建,然后它开始构建调试版本,它给了我:

The problem is if I try to build it with Visual Studio: the release version is built correctly, and then it begins to build the debug version, and it gives me:

将文件从"obj \ x86 \ Debug \ ConsoleApplication64.exe"复制到"bin \ Debug \ ConsoleApplication64". c:\ WINDOWS \ Microsoft.NET \ Framework \ v4.0.30319 \ Microsoft.Common.targets(2868,9):错误MSB3021:无法将文件"obj \ x86 \ Debug \ ConsoleApplication64.exe"复制到"bin \ Debug \ ConsoleApplication64.exe".找不到文件'obj \ x86 \ Debug \ ConsoleApplication64.exe'.

Copying file from "obj\x86\Debug\ConsoleApplication64.exe" to "bin\Debug\ConsoleApplication64. c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(2868,9): error MSB3021: Unable to copy file "obj\x86\Debug\ConsoleApplication64.exe" to "bin\Debug\ConsoleApplication64.exe". Could not find file 'obj\x86\Debug\ConsoleApplication64.exe'.

前提条件:

  • Windows XP SP3 ITA
  • Visual Studio 2010 SP1简体中文
  • 该项目是C#4.0的一个空控制台应用程序(从技术上讲不是,但是我可以重现此问题).

(请注意,为了激活这些消息,我已经激活了详细信息:正常菜单工具选项项目和解决方案构建并运行 MSBuild项目构建输出的详细程度.

(Note that to have those messages I've activated the verbosity: normal from menu ToolsOptionsProjects and SolutionsBuild and RunMSBuild project build output verbosity.

在比较两个半"运行的输出之后,不同之处在于在工作"的一半中调用了csc可执行文件,而在另一半中则没有:

After comparing the output of the two "half" runs, the difference is that in the "working" half the csc executable is called, and in the other one it isn't:

发布一半:

任务"Csc"(TaskId:13) c:\ WINDOWS \ Microsoft.NET \ Framework \ v4.0.30319 \ Csc.exe/noconfig /nowarn:1701,1702/nostdlib +/platform:x86/errorreport:prompt/warn:4 /define:TRACE/引用:"C:\ Programmi \ Reference 程序集\ Microsoft \ Framework.NETFramework \ v4.0 \ Profile \ Client \ Microsoft.CSharp.dll /引用:"C:\ Programmi \ Reference 程序集\ Microsoft \ Framework.NETFramework \ v4.0 \ Profile \ Client \ mscorlib.dll" /引用:"C:\ Programmi \ Reference 程序集\ Microsoft \ Framework.NETFramework \ v4.0 \ Profile \ Client \ System.Core.dll /引用:"C:\ Programmi \ Reference 程序集\ Microsoft \ Framework.NETFramework \ v4.0 \ Profile \ Client \ System.dll /debug:pdbonly/filealign:512/optimize + /out:obj\x86\Release\ConsoleApplication64.exe/target:exe Program.cs Properties \ AssemblyInfo.cs"C:\ Documents and 设置\ m.alberti-cons \ Impostazioni locali \ Temp.NETFramework,Version = v4.0,Profile = Client.AssemblyAttributes.cs (TaskId:13)完成执行任务"Csc". (TaskId:13)

Task "Csc" (TaskId:13) c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /define:TRACE /reference:"C:\Programmi\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\Microsoft.CSharp.dll" /reference:"C:\Programmi\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\mscorlib.dll" /reference:"C:\Programmi\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Core.dll" /reference:"C:\Programmi\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\x86\Release\ConsoleApplication64.exe /target:exe Program.cs Properties\AssemblyInfo.cs "C:\Documents and Settings\m.alberti-cons\Impostazioni locali\Temp.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.cs" (TaskId:13) Done executing task "Csc". (TaskId:13)

调试一半:

任务"Csc"(任务ID:41) 完成执行任务"Csc". (TaskId:41)

Task "Csc" (TaskId:41) Done executing task "Csc". (TaskId:41)

经过更多测试后,我注意到如果两个部分使用相同的DefineConstants,则没有任何问题,并且一切正常,但是如果它们不同(例如在发布/调试中),则不会工作. :-(

After some more tests I've noticed that if the two halves use the same DefineConstants then there isn't any problem and everything works, but if they are different (as in release/debug) then it doesn't work. :-(

推荐答案

由于MSBuild的这个问题与之相关.

You can't build inside Visual Studio because of MSBuild's incremental build mechanism that skips targets marked as already run. The real question here is how to break this incremental build. This question is very related.

如果使用/verbosity=diag进行构建,您会注意到MSBuild报告了很多这样的结果:

If you build with /verbosity=diag you will notice MSBuild reports a bunch of these:

目标"AssignTargetPaths"已跳过.先前已成功构建.

Target "AssignTargetPaths" skipped. Previously built successfully.

Microsoft意识到了此行为,并考虑了设计.

Microsoft aware of this behavior and consider this by design.

一种可能的解决方法,对此我强烈建议,它正在使用

A possible workaround, which I strongly advise against it, is invoking the second build using the Exec task. The Exec task is merely a command line shell which will eat everything you will feed it with, but in your case it can break the incremental build chain.

<Exec Command="$(MSBuildToolsPath)\msbuild $(MSBuildProjectFile) /p:Configuration=Debug" Condition=" '$(Configuration)' == 'Release'" />

这篇关于我无法在Visual Studio中同时构建一个项目的多个配置,但是可以使用MSBuild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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