【问题标题】:Which CLR will an application that uses DLLs that have been compiled for different versions of .net use?使用为不同版本的 .net 编译的 DLL 的应用程序将使用哪个 CLR?
【发布时间】:2010-02-21 09:41:33
【问题描述】:

我认为这很明显,但我认为最好问一下:

如果一个应用程序 (exe) 被编译为在 .net 3.5 上运行,并且如果它使用的 dll 是为 .net 1.1 编译的,该 DLL 是否会自动使用 2.0 CLR,即父母?

反过来呢?

如果是这样,兼容性问题呢?

【问题讨论】:

    标签: .net clr


    【解决方案1】:

    EXE 文件决定进程将使用哪个 .NET 运行时版本。为早期版本的 .NET 编译的任何程序集都必须使用“进程版本”。这通常适用,因为 .NET 几乎没有重大更改。

    使用 .NET 1.1 DLL 的 .NET 3.5 应用程序将在 CLR 2.0 上运行该 DLL(.NET 2.0、3.0 和 3.5 都使用相同的 CLR 2.0 版本)。

    .NET 4 有一个新的 CLR,.NET 4 的新功能之一是 in-process side by side CLR hosting,它允许在同一进程中使用多个版本的 .NET,这可能会改变答案..

    【讨论】:

      【解决方案2】:

      没有。如果你的目标是 3.5 版本的框架,如果没有 3.5,它就不会神奇地使用 2.0。

      但您可以在app.exe.config 中使用assemblybinding bindingredirect 来指定替换版本:

      <configuration>
      
         ....
      
        <runtime>
          <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentassembly>
              <assemblyidentity name="System" culture="neutral" publickeytoken="969db8053d3322ac" />
              <bindingredirect newVersion="2.0.0.0" oldVersion="1.0.5000.0" />
            </dependentassembly>
            <dependentassembly>
              <assemblyidentity name="System.Windows.Forms" culture="neutral" publickeytoken="969db8053d3322ac" />
              <bindingredirect newVersion="2.0.0.0" oldVersion="1.0.5000.0" />
            </dependentassembly>      
          </assemblybinding>
        </runtime>
      
      </configuration>
      

      Redirecting Assembly Versions

      【讨论】:

      • 米奇。你的回答不清楚。您是说 DLL 不会使用父运行时吗?如果没有,是否加载了 2 个 CLR?
      • @Bobby Alexander:请您澄清您的问题。
      • Mitch,我想知道的是:如果一个 exe 是为 framework 3.5 构建的,但它使用的 DLL(引用)是在 .net 1.1 上构建的,那么 dll 是否会自动在 2.0 CLR 上运行(和父母一样)?
      【解决方案3】:

      如果您的应用程序使用框架 3.5(实际上是 CLR 2)并加载为 CLR 1.0 或 CLR 1.1 编译的 dll,那么这些 dll 将自动使用 CLR 2。 你不能走另一条路 - 即。您无法将 CLR 2 dll 加载到 CLR 1 进程中而不会受到伤害。

      在 CLR 4 中,这些规则发生了一些变化,因为您现在可以在给定进程中拥有多个 CLR 实例,但这仅在您通过 COM 实例化对象时才相关,而不是在您通过正常反射加载时。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-01-31
        • 1970-01-01
        • 2010-09-24
        • 1970-01-01
        • 1970-01-01
        • 2011-12-18
        • 2023-03-27
        相关资源
        最近更新 更多