title: Why is there a difference in behaviour of an application built in VS 2010 v.s. VS 2012?
body: <p>I was checking whether installing .NET 4.5 on our build machines changes the output IL image generated by VS 2010.</p>
  
  <p>Since I know the behaviour of foreach has changed in .NET 4.5 to avoid issues due to <a href="http://blogs.msdn.com/b/ericlippert/archive/2009/11/12/closing-over-the-loop-variable-considered-harmful.aspx" rel="nofollow noreferrer">Access to Modified closure</a>, I chose a simple application that exhibited the behaviour.</p>
  
  <pre><code>  class Program
      {
          private static void Main(string[] args)
          {
              var contents = new List&lt;Func&lt;int&gt;&gt;();
              var s = new StringBuilder();
  
              int[] values = new int[] { 4, 5, 6 };
  
              foreach (int value in values)
              {
                  contents.Add(() =&gt; value);
              }
  
              for (var k = 0; k &lt; contents.Count; k++)
                  s.Append(contents[k]());
  
              Console.WriteLine(s);
          }
  </code></pre>
  
  <p><strong>VS 2010 output</strong>: 666</p>
  
  <p><strong>VS 2012 output</strong>: 456</p>
  
  <p>I created a console application in VS 2010 and a console application with the same code in VS 2012 (both targeted .NET 4).</p>
  
  <p>However, both the console applications exhibited different behaviours based on the IDE they were built with. In the build output, I checked that both had nearly similar build arguments. So I was wondering how the end executable exhibited different behaviour? .NET 4.5 is an in-place upgrade, so the compiler for both IDEs must be the same.</p>
  
  <p>NOTE: I did have a look at a related question: <a href="https://stackoverflow.com/questions/13327224/different-linq-answer-in-vs-2010-and-vs-2012">Different LINQ Answer in VS 2010 and VS 2012</a> but it did not answer my question on why the executable behaviour differed. </p>
  
  <p><strong>EDIT 1:</strong>
  As <a href="https://stackoverflow.com/users/65235/mletterle">mletterle</a> mentioned, I did try building the code using the commandline in the output window of VS 2010 in a VS 2010 command prompt. The resulting output behaved as if it was built with VS 2012.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I am posting the output present in Output Window:</p>
  
  <p><strong>VS 2010:</strong>
  Build started 12/20/2012 11:04:56 PM.</p>
  
  <blockquote>
    <p>CoreClean:   Creating directory "obj\x86\Debug\".
    GenerateTargetFrameworkMonikerAttribute: Skipping target
    "GenerateTargetFrameworkMonikerAttribute" because all output files are
    up-to-date with respect to the input files. CoreCompile:<br>
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig
    /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4
    /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US
    /highentropyva- /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\Microsoft.CSharp.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Data.DataSetExtensions.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Data.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Xml.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Xml.Linq.dll"
    /debug+ /debug:full /filealign:512 /optimize-
    /out:obj\x86\Debug\TestConsoleApp.exe /target:exe /utf8output
    Program.cs Properties\AssemblyInfo.cs
    "C:\Users\105044960\AppData\Local\Temp.NETFramework,Version=v4.0.AssemblyAttributes.cs"
    _CopyAppConfigFile: Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
    CopyFilesToOutputDirectory:   Copying file from
    "obj\x86\Debug\TestConsoleApp.exe" to "bin\Debug\TestConsoleApp.exe". 
    TestConsoleApp -> C:\Users\105044960\Documents\Visual Studio
    2010\Projects\TestConsoleApp\TestConsoleApp\bin\Debug\TestConsoleApp.exe
    Copying file from "obj\x86\Debug\TestConsoleApp.pdb" to
    "bin\Debug\TestConsoleApp.pdb".</p>
  </blockquote>
  
  <p><strong>VS 2012:</strong></p>
  
  <blockquote>
    <p>1>CoreClean: 1>  Deleting file "c:\users\105044960\documents\visual
    studio
    11\Projects\TestConsoleApp\TestConsoleApp\bin\Debug\TestConsoleApp.exe".
    1>  Deleting file "c:\users\105044960\documents\visual studio
    11\Projects\TestConsoleApp\TestConsoleApp\bin\Debug\TestConsoleApp.pdb".
    1>  Deleting file "c:\users\105044960\documents\visual studio
    11\Projects\TestConsoleApp\TestConsoleApp\obj\Debug\TestConsoleApp.csprojResolveAssemblyReference.cache".
    1>  Deleting file "c:\users\105044960\documents\visual studio
    11\Projects\TestConsoleApp\TestConsoleApp\obj\Debug\TestConsoleApp.exe".
    1>  Deleting file "c:\users\105044960\documents\visual studio
    11\Projects\TestConsoleApp\TestConsoleApp\obj\Debug\TestConsoleApp.pdb".
    1>GenerateTargetFrameworkMonikerAttribute: 1>Skipping target
    "GenerateTargetFrameworkMonikerAttribute" because all output files are
    up-to-date with respect to the input files. 1>CoreCompile: 1> 
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig
    /nowarn:1701,1702,2008 /nostdlib+ /platform:AnyCPU /errorreport:prompt
    /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US
    /highentropyva- /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\Microsoft.CSharp.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Data.DataSetExtensions.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Data.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Xml.dll"
    /reference:"C:\Program Files (x86)\Reference
    Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Xml.Linq.dll"
    /debug+ /debug:full /filealign:512 /optimize-
    /out:obj\Debug\TestConsoleApp.exe /target:exe /utf8output Program.cs
    Properties\AssemblyInfo.cs
    "C:\Users\105044960\AppData\Local\Temp.NETFramework,Version=v4.0.AssemblyAttributes.cs"
    1>CopyFilesToOutputDirectory: 1>  Copying file from
    "obj\Debug\TestConsoleApp.exe" to "bin\Debug\TestConsoleApp.exe". 1> 
    TestConsoleApp -> C:\Users\105044960\Documents\Visual Studio
    11\Projects\TestConsoleApp\TestConsoleApp\bin\Debug\TestConsoleApp.exe
    1>  Copying file from "obj\Debug\TestConsoleApp.pdb" to
    "bin\Debug\TestConsoleApp.pdb".</p>
  </blockquote>