【问题标题】:I can't build multiple configuration(s) of a project at the same time in Visual Studio, but I can with MSBuild我无法在 Visual Studio 中同时构建项目的多个配置,但我可以使用 MSBuild
【发布时间】:2012-02-03 10:59:43
【问题描述】:

我想在一个项目中同时构建两个配置。假设我想构建发布版本,但我什至想构建调试版本(反之亦然)。

Use a single Visual Studio solution to build both x86 and x64 at the same time? 开始我尝试添加到 .csproj:

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

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

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

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

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

将文件从“obj\x86\Debug\ConsoleApplication64.exe”复制到“bin\Debug\ConsoleApplication64.exe” 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'。

前置条件:

  • Windows XP SP3 ITA
  • Visual Studio 2010 SP1 英文版
  • 该项目是 C# 4.0 的空控制台应用程序(技术上不是,但我可以重现该问题)。

(请注意,要获得这些消息,我已经激活了详细程度:从菜单正常 ToolsOptionsProjects and Solutions → 构建并运行 → MSBuild 项目构建输出详细程度

比较两次“一半”运行的输出后,区别在于“工作”一半中调用了 csc 可执行文件,而另一半则没有:

释放一半:

任务 "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 程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\Microsoft.CSharp.dll" /reference:"C:\Programmi\Reference 程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\mscorlib.dll" /reference:"C:\Programmi\Reference 程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Core.dll" /reference:"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 和 设置\m.alberti-cons\Impostazioni locali\Temp.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.cs" (TaskId:13) 完成执行任务“Csc”。 (TaskId:13)

调试一半:

任务 "Csc" (TaskId:41) 完成执行任务“Csc”。 (TaskId:41)

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

【问题讨论】:

  • 能否请您先尝试在调试配置中构建 Msbuild,然后尝试在发布配置中构建?
  • @Samselvaprabu 然后它可以工作,但实际上它什么也没做。明确一点:Build Debug,Build Release(+Debug):没有错误,但是:Build Debug,添加几行代码(Console.WriteLine("Hello World");),Build Release,Debug版本没有重建,但是没有错误。跨度>
  • 你的 Visual Studio 是 /p:Platform=x86 还是 anycpu?
  • @Samselvaprabu 我正在使用股票控制台应用程序,因此它具有 x86 的调试和发布的配置,但不适用于 anycpu。

标签: visual-studio-2010 msbuild


【解决方案1】:

您无法在 Visual Studio 中构建,因为 MSBuild 的 incremental build 机制会跳过标记为已运行的目标。这里真正的问题是如何打破这种增量构建。 This 问题很相关。

如果您使用 /verbosity=diag 构建,您会注意到 MSBuild 报告了这些:

已跳过目标“AssignTargetPaths”。以前构建成功。

Microsoft 意识到此行为并考虑此by design

我强烈建议不要这样做的一种可能的解决方法是使用Exec 任务调用第二个构建。 Exec 任务只是一个命令行 shell,它会吃掉你要喂它的所有东西,但在你的情况下,它可能会破坏增量构建链。

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

【讨论】:

  • Target "AssignTargetPaths" skipped. Previously built successfully. 存在于诊断版本的两半中。我什至尝试将 true 放在三个 ProjectGroup 中(通用的和用于调试和发布的),但它没有改变任何东西。
  • 这只是一个例子。如果你仔细观察,你会发现一堆Previously built successfullyskipped, due to false condition。在内部,VS 决定何时不重建,但该过程可能会被黑客入侵。 this may give you a clue
猜你喜欢
  • 2018-09-23
  • 2018-03-03
  • 2019-09-24
  • 1970-01-01
  • 1970-01-01
  • 2016-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多