【发布时间】: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 的空控制台应用程序(技术上不是,但我可以重现该问题)。
(请注意,要获得这些消息,我已经激活了详细程度:从菜单正常 Tools → Options → Projects 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