C#编译器如何决定发出可重定位的程序集引用? [英] How does the C# compiler decide to emit retargetable assembly references?
问题描述
可重定位的程序集引用已为.NET Compact Framework引入,现已用于支持可移植类库.
Retargetable assembly references have been introduced for the .NET Compact Framework and are now used to support Portable Class Libraries.
基本上,编译器发出以下MSIL:
Basically, the compiler emits the following MSIL:
.assembly extern retargetable mscorlib
{
.publickeytoken = (7C EC 85 D7 BE A7 79 8E )
.ver 2:0:5:0
}
C#编译器如何理解它必须发出可重新定向的引用,以及如何强制C#编译器甚至在可移植类库之外也发出此类引用?
How does the C# compiler understand it has to emit a retargetable reference, and how to force the C# compiler to emit such reference even outside of a portable class library?
推荐答案
对于程序集本身,它是一个程序集标志,即[assembly:AssemblyFlags(AssemblyNameFlags.Retargetable)].
For the assembly itself, it's an assembly flag, ie [assembly: AssemblyFlags(AssemblyNameFlags.Retargetable)].
请注意,此标志在平台程序集之外是没有意义的-自定义程序集无法重定向.
Make note that this flag is meaningless outside of platform assemblies - custom assemblies cannot be retargetable.
对于引用,它将作为名称的一部分从所引用的程序集中复制.
For references, it's copied as part of the name from the assembly being referenced.
这篇关于C#编译器如何决定发出可重定位的程序集引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!