为什么编译器在编译友元程序集时需要程序集文件名?
Why does compiler need the assembly file name when compiling the friend assembly?
为什么编译器在编译友元程序集时需要程序集文件名?
我正在阅读 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.
上面摘录的意思是程序集所在的文件和程序集同名。但事实并非如此,因为强命名的程序集名称由程序集的名称、区域性、public 密钥和版本号组成。
否则我得出结论,无法给程序集名称下定义,因为名称的定义假设我们已经知道名称是什么了。因为name = name + culture + public key + version number.
所以,谁能简单解释一下为什么文件名对朋友汇编编译很重要?文件名和程序集名之间的关系是什么?
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.
OP:
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....
当然,简单的文本名称可能源自签署时的 assembly/filename,但这是偶然的。
OP:
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)?
为什么编译器在编译友元程序集时需要程序集文件名?
我正在阅读 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.
上面摘录的意思是程序集所在的文件和程序集同名。但事实并非如此,因为强命名的程序集名称由程序集的名称、区域性、public 密钥和版本号组成。
否则我得出结论,无法给程序集名称下定义,因为名称的定义假设我们已经知道名称是什么了。因为name = name + culture + public key + version number.
所以,谁能简单解释一下为什么文件名对朋友汇编编译很重要?文件名和程序集名之间的关系是什么?
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.
OP:
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....
当然,简单的文本名称可能源自签署时的 assembly/filename,但这是偶然的。
OP:
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)?