我想在一个项目中同时构建两个配置。假设当我想构建发行版本,但我什至想构建调试版本(反之则不然)。
从...开始使用单个 Visual Studio 解决方案同时构建 x86 和 x64?我尝试添加到 .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 → 项目与解决方案 → 构建并运行 → MSBuild 项目构建输出详细信息.
比较两个“一半”运行的输出后,不同之处在于,在“工作”一半中csc
可执行文件被调用,而在另一个中则没有:
释放一半:
任务“Csc”(任务 ID:13)
c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig
/nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:提示 /warn:4
/define:TRACE /reference:"C:\Programmi\Reference
程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\Microsoft.CSharp.dll”
/参考:“C:\ Programmi \参考
程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\mscorlib.dll”
/参考:“C:\ Programmi \参考
程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Core.dll”
/参考:“C:\ Programmi \参考
程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.dll”
/调试:pdbonly /文件对齐:512 /优化+
/out:obj\x86\Release\ConsoleApplication64.exe /target:exe Program.cs
Properties\AssemblyInfo.cs“C:\Documents 和
设置\m.alberti-cons\Impostazioni
locali\Temp.NETFramework,版本=v4.0,配置文件=Client.AssemblyAttributes.cs”
(TaskId:13) 完成执行任务“Csc”。 (任务编号:13)
调试一半:
任务“Csc”(任务 ID:41)
完成执行任务“Csc”。 (任务编号:41)
经过更多测试后,我注意到如果两半使用相同的DefineConstants
那么就没有任何问题并且一切正常,但是如果它们不同(如在发布/调试中),那么它就不起作用。 :-(