如何识别程序集是使用 .NET 4.5 编译的/为 .NET 4.5 编译的,而不是 .NET 4.0? [英] How to identify that an assembly has been compiled with/for .NET 4.5, as opposed to .NET 4.0?

查看:35
本文介绍了如何识别程序集是使用 .NET 4.5 编译的/为 .NET 4.5 编译的,而不是 .NET 4.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些构建代理正在通过 TeamCity 设置为我们构建 .NET 代码,我开始怀疑尽管有项目设置,但它们是否输出 .NET 4.5 构建的程序集.我的怀疑来自这样一个事实,我不知道 Windows 2012 Server 是开箱即用的 .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(.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

我尝试在仅安装了 .NET 4.0 的情况下启动应用程序 Windows 7,并且它启动了,但是如果确定 一切 是否有效的唯一方法是测试 一切,那么我宁愿多尝试一下,看看它是否首先使用正确的版本构建.

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 使用此属性来验证机器上是否存在正确的版本,如果没有安装,则提示用户自动安装.

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.

这篇关于如何识别程序集是使用 .NET 4.5 编译的/为 .NET 4.5 编译的,而不是 .NET 4.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆