是依赖于.NET程序集清单晋升?清单、程序、依赖于、NET

2023-09-05 02:03:11 作者:⌒尐掱栤涼だ

我建立与VS2010的组件,它有一个普通的参考.NET 4.0。

I build an assembly with VS2010, and it has a plain vanilla reference to .NET 4.0.

它也有一个参考Ionic.Zip,其中引用了.NET 2.0。

It also has a reference to Ionic.Zip, which has a reference to .NET 2.0.

当我看清单与ILDASM,我看到.NET的两个版本我组装的直接依赖,再加上2.0的离子组件下再列出。

When I look at the manifest with ildasm, I see both versions of .NET as direct dependencies of my assembly, plus 2.0 listed again under the Ionic assembly.

这是正常的,或者是有一些2.0的相依性,我只是没有看到?

Is this normal, or is there some 2.0 dependency that I'm just failing to see?

推荐答案

这是正常的,你会看到那些由公共类型在传统的装配露出任何框架类.NET 2.0的程序集引用。例如,编译VS2008与此code一个类库项目:

This is normal, you'll see .NET 2.0 assembly references for any framework classes that are exposed by the public types in the legacy assembly. For example, a class library project compiled in VS2008 with this code:

using System;
using System.Text;

public class Class1 {
    public static void Run(out StringBuilder sb) {
        sb = new StringBuilder();
    }
}

和在VS2010控制台模式的应用程序,目标4.0中使用:

And used in a VS2010 console mode app that targets 4.0:

using System;
using System.Text;

class Program {
    static void Main(string[] args) {
        StringBuilder sb;
        Class1.Run(out sb);
    }
}

生成的程序集引用在其清单如下:

Produces assembly references in its manifest like this:

// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly extern ClassLibrary3
{
  .ver 1:0:0:0
}
.assembly extern mscorlib as mscorlib_2
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}

请注意引用到2.0版本的mscorlib程序,命名为mscorlib_2。这是在运行时解决。有没有从融合日志的迹象,这是以往任何时候要求解决mscorlib_2集引用。获得创建的StringBuilder类对象是4.0版本。这可能意味着CLR程序集加载器重定向的版本。我不知道,做了映射,猜测这是硬codeD任何配置的。

Note the reference to the 2.0 version of mscorlib, named "mscorlib_2". This is resolved at runtime. There is no sign from the fusion log that it was ever asked to resolve the mscorlib_2 assembly reference. The StringBuilder class object that get created is the 4.0 version. Which probably means that the CLR assembly loader is redirecting the version. I'm not aware of any config that does the mapping, guessing at this being hard-coded.

这当然是可能破坏行为被永远只能用.NET程序集的2.0-v3.5sp1版本测试code。我没有听说过一个案例呢。

This is of course potentially breaking behavior for the code that was only ever tested with v2.0-v3.5sp1 versions of the .NET assemblies. I haven't heard of a single case yet.