gpt4 book ai didi

c# - 为什么编译器在编译友元程序集时需要程序集文件名?

转载 作者:行者123 更新时间:2023-11-30 22:51:31 25 4
gpt4 key购买 nike

为什么编译器在编译友元程序集时需要程序集文件名?

我正在阅读CLR via C#这本书,我看到了以下摘录:

Note that the C# compiler requires you to use the /out: compiler switch when compiling the friend assembly (the assembly that does not contain the InternalsVisibleTo attribute). The switch is required because the compiler needs to know the name of the assembly being compiled in order to determine if the resulting assembly should be considered a friend assembly. You would think that the C# compiler could determine this on its own since it normally determines the output file name on its own; however, the compiler doesn’t decide on an output file name until it is finished compiling the code. So requiring the /out: compiler switch improves the performance of compiling significantly.

Also, if you are compiling a module (as opposed to an assembly) using C#’s /t:module switch, and this module is going to become part of a friend assembly, you need to compile the module by using the C# compiler’s /moduleassemblyname: switch as well. This tells the compiler what assembly the module will be a part of so the compiler can allow code in the module to access the other assembly’s internal types.

上面的摘录意味着放置程序集的文件与程序集具有相同的名称。但事实并非如此,因为强命名的程序集名称由程序集的名称、区域性、公钥和版本号组成。

否则我得出的结论是无法给程序集名称下定义,因为名称的定义假设我们已经知道名称是什么。因为name = name + culture + public key + version number.

那么,有人可以简单地解释一下为什么文件名对于 friend 汇编编译很重要吗?文件名和程序集名之间的关系是什么?

最佳答案

Why does compiler need the assembly file name when compiling the friend assembly?

在您提供的报价单中说明:

You would think that the C# compiler could determine this on its own since it normally determines the output file name on its own; however, the compiler doesn’t decide on an output file name until it is finished compiling the code. So requiring the /out: compiler switch improves the performance of compiling significantly.

运算符(operator):

The excerpt above means that the file in which an assembly is put and the assembly have the same name. But that is not the case, because a strongly named assembly name consists of assembly's name, culture, public key, and version number.

它根本没有这么说,那不是强命名 (SN​​) 程序集的定义。

MSDN:

A strong name consists of the assembly's identity — its simple text name, version number, and culture information (if provided) — plus a public key and a digital signature. More....

当然,简单的文本名称可能源自签名时的程序集/文件名,但这是偶然的。

运算符(operator):

Otherwise, I come to a conclusion that it is impossible to give a definition to the assembly name, because the definition of the name assumes that we already know what the name is. Because name = name + culture + public key + version number.

强命名(我假设我们还在这一点上)程序集发生在程序集生成之后。你不能签署那不存在。如果它存在,它有一个简单的文本名称。

另外,为什么我们现在要讨论程序集的 .NET 强命名 (SN​​)?

关于c# - 为什么编译器在编译友元程序集时需要程序集文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59096325/

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