gpt4 book ai didi

c# - 依赖程序集的版本是否存储在引用程序集中?

转载 作者:太空宇宙 更新时间:2023-11-03 22:08:51 25 4
gpt4 key购买 nike

以下说法引自this article在 MSDN 中。

... strong-name signing makes servicing more complicated. Under current versioning policy, an assembly will always attempt to load the exact version of the assembly it was built against. If, for example, your application was built against version 1.0.0.0 of a strong-named assembly and you fix a bug in the assembly, bumping the version number to 1.0.0.1, the existing application will not find the updated assembly.

现在,假设存在两个强名称程序集(用 C# 或 VB.net 编写),即 X 和 Y,并且 X 依赖于 Y。

  1. Y 的版本在编译时是否存储在 X 的某处?
  2. Y 中使用的公钥是否存储在 X 中的某处以避免代码改变攻击方式?
  3. 如果在 CLR 加载 Y 时检查 Y 的版本,如果 Y 会发生什么是动态加载的,没有编译时引用?

如果可能,请在您的答案中附上引用资料。

最佳答案

您可以在编译或运行时引用强命名程序集。

编译时间:

When you use compile-time referencing, the compiler automatically gets the public key of the targeted strong-named assembly and places it in the assembly reference of the assembly being compiled.

因此它将存储在 assembly manifest 中:

Information on referenced assemblies: A list of other assemblies that are statically referenced by the assembly. Each reference includes the dependent assembly's name, assembly metadata (version, culture, operating system, and so on), and public key, if the assembly is strong named.

运行时间:

When you make a run-time reference to a strong-named assembly (for example, by using the Assembly.Load or Assembly.GetType method), you must use the display name of the referenced strong-named assembly. The syntax of a display name is as follows:

<assembly name>, <version number>, <culture>, <public key token>

显然,您应该在运行时手动指定版本。

参见 How to: Reference a Strong-Named Assembly

关于c# - 依赖程序集的版本是否存储在引用程序集中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7419670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com