我的程序集实际运行哪个版本的.Net框架? [英] Which version of the .Net framework is my assembly actually running?

查看:63
本文介绍了我的程序集实际运行哪个版本的.Net框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需进行一些设置.我们已经安装了.Net框架3.5、4.0、4.5和4.6.1.

Just a little setup. We have the .Net framework 3.5, 4.0, 4.5, and 4.6.1 installed.

如果我们使用.Net Framework 3.5构建.Net应用程序或程序集,然后将app.config设置为使用4.6.1的单个受支持运行时运行:

If we build a .Net application or assembly using .Net framework 3.5 and then we set the app.config to run using a single supported runtime of 4.6.1:

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup>

实际上正在使用哪个版本的框架?

这个问题来自阅读这篇文章:

This question came from from reading this post: How do I force an application compiled to target .NET Framework 4 to run under .NET framework 4.6.1?. @Hans Passant states that the TargetFrameworkAttribute will dictate how the framework will behave and he talks about there being switches that cause specific code to run, etc.. However, I haven't found anything that explains which version of the core .Net framework will be running in this scenario.

对.Net框架的任何调用都将使用.Net 3.5代码库,.Net 4.0代码库(由于4.0 clr版本),还是将运行最新,最大的.Net 4.6.1代码库,因为那是使用clr 4.0安装的最新版本吗?

Will any calls to the .Net framework use the .Net 3.5 code base, the .Net 4.0 code base (because of the 4.0 clr version), or will the latest and greatest .Net 4.6.1 code base be run because that is the latest version installed using the clr 4.0?

显示未明确声明运行时版本的清单.

To show the manifest that does not specifically state the runtime version.

// Metadata version: v2.0.50727
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly ConsoleApplicationVersionTest
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.

  // --- The following custom attribute is added automatically, do not uncomment -------
  //  .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) 

  .custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 1D 43 6F 6E 73 6F 6C 65 41 70 70 6C 69 63   // ...ConsoleApplic
                                                                                              61 74 69 6F 6E 56 65 72 73 69 6F 6E 54 65 73 74   // ationVersionTest
                                                                                              00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 1D 43 6F 6E 73 6F 6C 65 41 70 70 6C 69 63   // ...ConsoleApplic
                                                                                                61 74 69 6F 6E 56 65 72 73 69 6F 6E 54 65 73 74   // ationVersionTest
                                                                                                00 00 ) 
  .custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 12 43 6F 70 79 72 69 67 68 74 20 C2 A9 20   // ...Copyright .. 
                                                                                                  20 32 30 31 36 00 00 )                            //  2016..
  .custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 34 36 36 31 33 34 32 33 2D 38 39 34 30   // ..$46613423-8940
                                                                                                  2D 34 39 36 65 2D 61 31 37 32 2D 37 36 36 31 31   // -496e-a172-76611
                                                                                                  64 30 66 31 32 32 38 00 00 )                      // d0f1228..
  .custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 31 2E 30 2E 30 2E 30 00 00 )             // ...1.0.0.0..
  .hash algorithm 0x00008004
  .ver 1:0:0:0
}
.module ConsoleApplicationVersionTest.exe
// MVID: {11493526-C9AC-45F0-9784-D7712809998C}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x00000000010B0000

推荐答案

我们已经安装了.Net框架3.5、4.0、4.5和4.6.1

We have the .Net framework 3.5, 4.0, 4.5, and 4.6.1 installed

那是不准确的,这样的配置是不可能的.规则是,您只能安装一个版本的.NET 2.0到3.5,它针对v2.0.50727运行时.并安装了一个版本的.NET 4.0到4.6.2,它的目标是v4.0.30319运行时.

That is not accurate, such a configuration is not possible. The rule is that you can have only one version of .NET 2.0 through 3.5 installed, it targets the v2.0.50727 runtime. And one version of .NET 4.0 through 4.6.2 installed, it targets the v4.0.30319 runtime.

因此您的计算机可能已经安装了4.0.当您安装4.5时,它会覆盖 4.0安装.没有留下任何痕迹.4.5完全有能力运行针对4.0的程序,Microsoft花费了大量精力来确保4.5与4.0向后兼容.同样,当您安装4.6.1时,它会覆盖4.5

So your machine might have had 4.0 installed. When you installed 4.5 it overwrote the 4.0 install. No trace of it is remaining. 4.5 is quite capable of running programs that target 4.0, Microsoft spent an enormous amount of effort to ensure that 4.5 is backwards compatible with 4.0. And likewise, when you installed 4.6.1 it overwrote 4.5

//元数据版本:v2.0.50727

// Metadata version: v2.0.50727

您张贴的ildasm.exe转储清楚地表明该程序集以2.0.50727运行时为目标.非常简单,它将在3.5版本上运行.它将在2.0安装中运行得一样好,它不使用在3.0和3.5中添加的任何程序集.也许这就是您的提示,Microsoft在添加新程序集时会增加框架版本.仅当它创建新的运行时版本时,您才能进行其他并行安装.不太可能很快发生这种情况,更不用说采用完全不同方法的.NETCore了.

The ildasm.exe dump you posted clearly shows that the assembly targets the 2.0.50727 runtime. So easy peasy, it is going to run on the 3.5 version. It will run just as well on a 2.0 install, it doesn't use any assemblies that were added in 3.0 and 3.5. Maybe that's your cue, Microsoft increments the framework version when it adds new assemblies. Only when it creates a new runtime version can you have another side-by-side install. That's not very likely to happen anytime soon, not counting .NETCore which took a completely different approach.

这篇关于我的程序集实际运行哪个版本的.Net框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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