简体   繁体   English

确定是否正在使用GAC'ed和NGen'ed程序集

[英]Determine if GAC'ed & NGen'ed assemblies are being used

How do I determine if the Native images are being used without the Loader verifing the signature of the assembly at runtime, or even using the GAC'ed assembly? 如何确定是否在不使用Loader在运行时验证程序集签名的情况下使用本机映像,甚至不使用GAC的程序集?

I have complex system that we're experimenting with NGen but currently we're running the exe from the folder where all the DLL's are located due to a lot of late binding dependencies, looking at Process Explorer, it looks like the Native images are being used, but how can I be sure I'm getting the full benefit and eliminating the Loader Verification step? 我有一个正在尝试NGen的复杂系统,但由于存在大量后期绑定依赖关系,目前我们正在从所有DLL所在的文件夹中运行exe,查看Process Explorer,看起来本机映像正在使用,但如何确定我会获得全部利益并取消Loader Verification步骤?

Cheers, Graeme. 干杯,Graeme。

Update: I'm getting lots of this sort of thing from the Assembly Binding Log viewer: 更新:我从程序集绑定日志查看器中得到了很多这类信息:

LOG: [Level 1]Start validating IL dependency MyCompany.Entities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7cd8595f4671c5dd.
LOG: Dependency evaluation succeeded.

and at the end 最后

LOG: Validation of dependencies succeeded.
LOG: Start loading all the dependencies into load context.
LOG: Loading of dependencies succeeded.
LOG: Bind to native image succeeded.
Native image has correct version information.
Attempting to use native image C:\Windows\assembly\NativeImages_v2.0.50727_32\MyCompany.Mylibrary#\4710bb8309419d707681bd360088181f\MyCompany.MyLibrary.MyClass.ni.dll.
ZAP: Native image has been relocated.
Native image successfully used.

So it's using the Native images but still verifying them, ie not using the GAC version even though that's where I created the Native image from, Like so: 因此,它使用的是本机映像,但仍在对其进行验证,即,即使那是我从中创建本机映像的地方,也不使用GAC版本,就像这样:

ngen install "MyCompany.Entites, Version=2.0.0.0, Culture=neutral, PublicKeyToken=7cd8595f4671c5dd, processorArchitecture=MSIL"

Footnote: This articles seems to imply that if the assemblies are not loaded from the GAC then the verification process will offset the NGen advantages? 脚注:本文似乎暗示,如果未从GAC加载程序集,则验证过程是否可以抵消NGen的优势? CLR Inside Out - Improving Application Startup Performance (MSDN) 由内而外进行CLR-提高应用程序启动性能(MSDN)

Update - As Nobugz has pointed out in a comment below, the verification step mentioned above is not performed since 3.5 SP1 see: MSDN Docs on NGen 更新 -正如Nobugz在下面的评论中所指出的,自3.5 SP1起,不再执行上述验证步骤,请参阅: NGen上的MSDN文档

You can easily see it from the Fuslogvw.exe tool. 您可以从Fuslogvw.exe工具轻松看到它。 Start it from the Visual Studio Command Prompt. 从Visual Studio命令提示符启动它。 Configure it with Log Categories = Native Images, Settings + Log all binds to disk. 使用日志类别=本机映像,设置+日志全部绑定到磁盘进行配置。 Run your program. 运行程序。 Back to fuslogvw, Refresh. 返回fuslogvw,刷新。 It will show you a list of all assemblies that got loaded. 它将显示所有已加载的程序集的列表。

Double-click an entry to see how the assembly got loaded. 双击一个条目以查看程序集如何加载。 If it came from the GAC, you'll see: 如果来自GAC,您将看到:

LOG: IL assembly loaded from C:\\Windows\\assembly\\GAC_MSIL\\blahblah 日志:从C:\\ Windows \\ assembly \\ GAC_MSIL \\ blahblah加载的IL程序集

If the Ngen-ed images was used, you'll see: 如果使用了Ngen版本的图像,您将看到:

LOG: Bind to native image succeeded. 日志:绑定到本地映像成功。

You can see if the assembly came from the GAC pretty easily: 您可以轻松地查看该程序集是否来自GAC:

Assembly assembly = Assembly.GetExecutingAssembly();

if (assembly.GlobalAssemblyCache)
{
    Console.WriteLine("I'm in the GAC!");
}

EDIT: found a way... 编辑:找到了一种方法...

In order to see if it is NGEN'd, you have to read the assembly directly and see if the Precompile Header field has data as per this page . 为了查看是否为NGEN,您必须直接阅读程序集,并查看Precompile Header字段是否具有此页面上的数据。 I'm a bit rusty on getting to that value, but that should do it. 我对达到该值有些不满意,但是应该做到这一点。 I don't see a way to figure it out via the reflection methods. 我没有找到通过反射方法弄清楚它的方法。

You can use the VMMAP . 您可以使用VMMAP There, all the .dll (assembly) have location details 在那里,所有.dll(程序集)都有位置详细信息

In details if your assembly is being loaded from "C:\\Windows\\assembly\\NativeImages(version)..." so your application are using the native image. 详细信息是否从“ C:\\ Windows \\ assembly \\ NativeImages(version)...”加载程序集,因此您的应用程序正在使用本机映像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM