如何识别装配已编译/于.NET 4.5,而不是.NET 4.0?而不是、如何识别、NET

2023-09-03 16:40:14 作者:失心

我有一些生成代理,它通过一个TeamCity的设置建设.NET code对我们来说,和我开始怀疑,尽管该项目的设置,他们输出的.NET 4.5内置集怀疑。我的怀疑来自于事实,我不知道的Windows 2012服务器来使用.NET 4.5或4.0的开箱即用,因此它是否曾经有过只有4.0或4.0的组件提供。

I have some build agents that is building .NET code for us through a TeamCity setup, and I'm beginning to wonder if despite the project settings, they're outputting .NET 4.5 built assemblies. My doubts come from the fact that I don't know if Windows 2012 Server came with .NET 4.5 or 4.0 out of the box and thus whether it ever has had only 4.0 or any of the 4.0 assemblies available.

如何看待磁盘上的一个组件,并确定它是否已建成使用.NET 4.0或4.5吗?

How can I look at a assembly on disk and determine whether it has been built with .NET 4.0 or 4.5?

由于是明证由Marc Gravell这篇博客文章,还有的是的在如何将这些组件构建的差异,即使我们实际上没有使用任何.NET 4.5组件/功能明确。

As is evident by this blog post by Marc Gravell, there are differences in how these assemblies are built, even though we may not actually use any .NET 4.5 assemblies / features specifically.

我尝试使用ILDASM在组件上,而是在已知.NET 4.5元数据的参考(0.1)控制台应用程序仍说4.0:

I tried using ILDASM on the assembly, but the metadata reference on a known .NET 4.5(.1) console application still says 4.0:

// Metadata version: v4.0.30319

我试着启动应用程序的Windows 7,只有安装了.NET 4.0,并开始,但如果只有这样,才能找出如果的所有的工作原理是通过测试的所有的,那么我宁愿尝试多一点,看看它是建立与正确版本的第一个。

I tried starting the application Windows 7 with only .NET 4.0 installed, and it starts, but if the only way to figure out if everything works is by testing everything, then I'd rather try a bit more to see if it is built with the right version first.

那么,这可能吗?

推荐答案

运行程序Ildasm.exe,并期待在清单中。你会看到TargetFrameworkAttribute:

Run ildasm.exe and look at the manifest. You'll see the TargetFrameworkAttribute:

.custom instance void [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = 
( 01 00 1A 2E 4E 45 54 46 72 61 6D 65 77 6F 72 6B   // ....NETFramework
  2C 56 65 72 73 69 6F 6E 3D 76 34 2E 35 01 00 54   // ,Version=v4.5..T
  0E 14 46 72 61 6D 65 77 6F 72 6B 44 69 73 70 6C   // ..FrameworkDispl
  61 79 4E 61 6D 65 12 2E 4E 45 54 20 46 72 61 6D   // ayName..NET Fram
  65 77 6F 72 6B 20 34 2E 35 )                      // ework 4.5

CLR使用这个属性来验证正确的版本为present在机器上,prompting用户得到它会自动安装,如果事实并非如此。

The CLR uses this attribute to verify that the correct version is present on the machine, prompting the user to get it automatically installed if it is not.