为什么我的 App.Config 有这个奇怪的程序集重定向?

Why does my App.Config have this strange Assembly Redirect?

  <dependentAssembly>
    <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
  </dependentAssembly>

我不明白 "old version"

上的 0.0.0.0- 前缀

意思是:

将版本 0.0.0.0-4.0.2.1(即任何版本 <=4.0.2.1)的所有请求重定向到版本 4.0.2.1

参考the documentation:

oldVersion : Required attribute.

Specifies the version of the assembly that was originally requested. The format of an assembly version number is major.minor.build.revision. Valid values for each part of this version number are 0 to 65535.

You can also specify a range of versions in the following format:

n.n.n.n - n.n.n.n

所以在你的例子中,我们有一个范围:

0.0.0.0-4.0.2.1

或任何小于或等于 4.0.2.1.

的版本