简体   繁体   English

如何检查应用程序的 .NET 版本?

[英]How do I check the .NET version of an App?

除了在只有 .NET Framework 3.5 版的计算机上运行之外,我如何检查 .NET 应用程序的版本?

.NET framework versioning went foobar after .NET 2.0. .NET 框架版本控制在 .NET 2.0 之后变成了 foobar。 An app targets a CLR version, it does so with the assembly metadata for the EXE.应用程序以CLR版本为目标,它使用 EXE 的程序集元数据来实现。 And there are currently four of them, 1.0, 1.1, 2.0 and 4.0.目前有四个版本,1.0、1.1、2.0 和 4.0。 Not counting special ones like used by the Compact Framework, Silverlight, Micro Framework.不包括像 Compact Framework、Silverlight、Micro Framework 使用的特殊的。

Framework versions 2.0, 2.0SP1, 2.0SP2, 3.0, 3.5 and 3.5SP1 all target the same CLR version, 2.0.50727.框架版本 2.0、2.0SP1、2.0SP2、3.0、3.5 和 3.5SP1 都针对相同的 CLR 版本 2.0.50727。 What's different between these releases is that they have additional assemblies available in later versions.这些版本之间的不同之处在于它们在更高版本中提供了额外的程序集。 The kind that support features like WPF, WCF and LINQ.支持 WPF、WCF 和 LINQ 等功能的那种。 They are additive, just more goodies added to something that was already pretty solid.它们是可添加的,只是在已经非常坚固的东西中添加了更多的好东西。 You never really have to guess what version of the framework your program needs, just open the References node in the Solution Explorer window and look at the assembly version numbers.您永远不必真正猜测您的程序需要哪个版本的框架,只需在“解决方案资源管理器”窗口中打开“引用”节点并查看程序集版本号。 Or set the Target Framework property in your project and work your way up until the compiler stops complaining.或者在您的项目中设置 Target Framework 属性并继续工作,直到编译器停止抱怨。

Back to your original question: the version you give your own .NET app is entirely up to you.回到您最初的问题:您提供自己的.NET 应用程序的版本完全取决于您。 Edit the [AssemblyVersion] attribute in the AssemblyInfo.cs file.编辑 AssemblyInfo.cs 文件中的 [AssemblyVersion] 属性。

I'm not sure to understand your question.我不确定是否理解您的问题。

If you want to check what version of the .NET framework is installed from a .NET application, check this:如果要检查从 .NET 应用程序安装的 .NET 框架版本,请检查以下内容:

http://geekswithblogs.net/lorint/archive/2006/01/30/67654.aspx http://geekswithblogs.net/lorint/archive/2006/01/30/67654.aspx

Reflector will tell you which framework version an assembly was built with. Reflector会告诉您程序集是用哪个框架版本构建的。 Open up each assembly in Reflector, open up the "References" and check the version shown for mscorlib and other system assemblies.在 Reflector 中打开每个程序集,打开“参考”并检查为 mscorlib 和其他系统程序集显示的版本。

If reflector can do it, it must be possible to work it out in code, at least in principle.如果反射器可以做到,那么它必须可以在代码中解决,至少在原则上是这样。 It looks like Reflector uses Cecil to inspect code.看起来 Reflector 使用Cecil来检查代码。

As far as I know this is not possible from within code.据我所知,这在代码中是不可能的。 A dll does not target a specific framework version, instead it runs under a particular CLR and uses particular assemblies. dll 不针对特定的框架版本,而是在特定的 CLR 下运行并使用特定的程序集。

For example, you could define a 3.0 app as one that runs under the 2.0 CLR, and uses assemblies that were released when .NET 3.0 was released.例如,您可以将 3.0 应用程序定义为在 2.0 CLR 下运行的应用程序,并使用在 .NET 3.0 发布时发布的程序集。 (You'd also need to check that it doesn't reference any assemblies that were released when 3.5 or 4.0 were released - even though these newer assemblies might only reference other assemblies that were released with version 2.0).# (您还需要检查它是否没有引用在 3.5 或 4.0 发布时发布的任何程序集 - 即使这些较新的程序集可能只引用其他随 2.0 版发布的程序集)。#

Realistically, the only way to do this would be to have a list off all assemblies released with a particular framework version, and do a cross-check of the assembly-under-test with this list.实际上,执行此操作的唯一方法是列出使用特定框架版本发布的所有程序集,并使用此列表对被测程序集进行交叉检查。

If you open the app in Visual Studio:如果在 Visual Studio 中打开应用:

  1. Right click the app project右键单击应用程序项目
  2. Select 'Properties'选择“属性”
  3. Select 'Application'选择“申请”

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM