[英]How does the C# compiler decide to emit retargetable assembly references?
Retargetable assembly references have been introduced for the .NET Compact Framework and are now used to support Portable Class Libraries. .NET Compact Framework引入了可重定向的程序集引用,现在用于支持可移植类库。
Basically, the compiler emits the following MSIL: 基本上,编译器会发出以下MSIL:
.assembly extern retargetable mscorlib
{
.publickeytoken = (7C EC 85 D7 BE A7 79 8E )
.ver 2:0:5:0
}
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? C#编译器如何理解它必须发出一个可重定向的引用,以及如何强制C#编译器甚至在可移植类库之外发出这样的引用?
For the assembly itself, it's an assembly flag, ie [assembly: AssemblyFlags(AssemblyNameFlags.Retargetable)]. 对于程序集本身,它是一个程序集标志,即[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. 对于引用,它被复制为被引用的程序集中名称的一部分。
Not sure if this will help, but the following file was auto-generated and included in the build. 不确定这是否有帮助,但以下文件是自动生成的并包含在构建中。
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(
".NETPortable,Version=v4.0,Profile=Profile4",
FrameworkDisplayName = ".NET Portable Subset")]
This might hint to the compiler to do some magic. 这可能暗示编译器要做一些魔术。
Edit: 编辑:
I think above makes a library portable. 我认为上面使一个库可移植。 From the command line I can see
/nostdlib+
is used, and a portable mscorlib.dll
is referenced (which I assume has the same attribute as mentioned above). 从命令行我可以看到
/nostdlib+
被使用,并且引用了一个可移植的mscorlib.dll
(我假设它具有与上面提到的相同的属性)。
"...\\Program Files\\Reference Assemblies\\Microsoft\\Framework.NETPortable\\v4.0\\Profile\\Profile4\\mscorlib.dll" “... \\ Program Files \\ Reference Assemblies \\ Microsoft \\ Framework.NETPortable \\ v4.0 \\ Profile \\ Profile4 \\ mscorlib.dll”
I've noticed by experimenting that the C# compiler would make an reference compiler as retargetable if the referenced assembly is marked as retargetable (a modifier on the .assembly
section in MSIL). 通过实验我已经注意到,如果引用的程序集被标记为retargetable(MSIL中
.assembly
部分的修饰符),C#编译器会将引用编译器设置为retargetable。 I did not find how the compiler decides to make the assembly retargetable, yet. 我没有找到编译器如何决定使程序集重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.