首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么在VS 2010 V.S.VS 2012中构建的应用程序的行为有差异?

为什么在VS 2010 V.S.VS 2012中构建的应用程序的行为有差异?
EN

Stack Overflow用户
提问于 2018-02-06 01:18:37
回答 2查看 0关注 0票数 0

我在检查是否安装.NET 4.5在我们的构建机器上更改了VS 2010生成的IL映像输出。

因为我知道了Foreach的行为已经改变了.NET 4.5以避免因访问修改后的闭包,我选择了一个简单的应用程序来展示这种行为。

  class Program
    {
        private static void Main(string[] args)
        {
            var contents = new List<Func<int>>();
            var s = new StringBuilder();

            int[] values = new int[] { 4, 5, 6 };

            foreach (int value in values)
            {
                contents.Add(() => value);
            }

            for (var k = 0; k < contents.Count; k++)
                s.Append(contents[k]());

            Console.WriteLine(s);
        }

2010年输出*666

2012年输出*456

我在VS 2010中创建了一个控制台应用程序,在VS 2012中创建了一个具有相同代码的控制台应用程序(都是针对目标.NET 4的)。

但是,这两个控制台应用程序都表现出了基于它们构建的IDE的不同行为。在构建输出中,我检查了两者的构建参数几乎相同。所以,我想知道终端可执行文件是如何表现出不同的行为的?.NET 4.5是一个就地升级,因此两个IDE的编译器必须相同.

2010年:建设于2012年12月20日开始

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:

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".

与2012年:

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".

EN

Stack Overflow用户

发布于 2018-02-06 10:21:29

但是.NET 4.5是一个就地升级到.NET 4。所以真的只有.NET 4在我的机器上。

更新1:

看来我们用了不同的“就地”升级定义。我对“就地”的用法是“在不同版本之间没有明显差异的升级”。中给出的定义。你链接到的文章以不同的方式使用它:“就位”在用法中是“使用相同的CLR,但添加了新的库”。

因为C#5与C#4不同,所以在我熟悉的用法中,这种更改并不是“就位”的。

因此,区别不在于所针对的CLR,而是所使用的语言版本--CLR是一个“就位”升级(都是4.0 CLR),但语言不是(VS 2010中的C#4,VS 2012年的C#5)。

更新2:

在.csproj文件(实际上是VisualStudio管理的msbuild文件),有一个属性指定目标框架。默认情况下,使用VisualStudio 2012生成的项目具有以下特性:

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

而VisualStudio 2010中的目标版本4的项目如下所示:

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

这将告诉VisualStudio在为一个或另一个目标框架构建时设置环境。虽然它看起来像是直接从命令提示符调用csc.exe,但实际上并非如此:msbuild项目实际上是正在处理的,它发生在“VisualStudio”的自定义进程环境中。

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档