简体   繁体   中英

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

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

.NET framework versioning went foobar after .NET 2.0. An app targets a CLR version, it does so with the assembly metadata for the EXE. And there are currently four of them, 1.0, 1.1, 2.0 and 4.0. Not counting special ones like used by the 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. 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. 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.

Back to your original question: the version you give your own .NET app is entirely up to you. Edit the [AssemblyVersion] attribute in the AssemblyInfo.cs file.

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:

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

Reflector will tell you which framework version an assembly was built with. Open up each assembly in Reflector, open up the "References" and check the version shown for mscorlib and other system assemblies.

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.

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.

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. (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).#

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:

  1. Right click the app project
  2. Select 'Properties'
  3. Select 'Application'

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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