title: I can't build multiple configuration(s) of a project at the same time in Visual Studio, but I can with MSBuild
body: <p>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).</p>
  
  <p>Starting with <em><a href="https://stackoverflow.com/questions/1574075/use-a-single-visual-studio-solution-to-build-both-x86-and-x64-at-the-same-time">Use a single Visual Studio solution to build both x86 and x64 at the same time?</a></em> I've tried adding to the .csproj:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Target Name="AfterBuild"&gt;
      &lt;MSBuild Condition=" '$(Configuration)' == 'Release' " Projects="$(MSBuildProjectFile)" Properties="Configuration=Debug" RunEachTargetSeparately="true" /&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>And if I try to build the project through MSBuild,</p>
  
  <pre><code>MSBuild ConsoleApplication64.csproj /p:Configuration=Release /p:Platform=x86
  </code></pre>
  
  <p>it works correctly. The two configurations are built correctly and everything is good.</p>
  
  <p>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:</p>
  
  <blockquote>
    <p>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'.</p>
  </blockquote>
  
  <p>Pre-conditions:</p>
  
  <ul>
  <li>Windows XP SP3 ITA</li>
  <li>Visual Studio 2010 SP1 English</li>
  <li>The project is an empty console application for C# 4.0 (technically it isn't, but I can reproduce the problem with that).</li>
  </ul>
  
  <p>(Note that to have those messages I've activated the verbosity: normal from menu <em>Tools</em> → <em>Options</em> → <em>Projects and Solutions</em> → <em>Build and Run</em> → <em>MSBuild project build output verbosity</em>.</p>
  
  <p>After comparing the output of the two "half" runs, the difference is that in the "working" half the <code>csc</code> executable is called, and in the other one it isn't:</p>
  
  <p>Release half:</p>
  
  <blockquote>
    <p>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)</p>
  </blockquote>
  
  <p>Debug half:</p>
  
  <blockquote>
    <p>Task "Csc" (TaskId:41)
    Done executing task "Csc". (TaskId:41)</p>
  </blockquote>
  
  <p>After some more tests I've noticed that if the two halves use the same <code>DefineConstants</code> then there isn't any problem and everything works, but if they are different (as in release/debug) then it doesn't work. :-(</p>