如何在程序启动时加载NetCore使用的所有DLL

How to load all DLLs used by NetCore at program startup

我正在 dotnet5 开发 wpf。

已添加 DevExpress 组件用于开发。

在发展过程中, 当您调用包含 DevExpress 控件的 subwindow 时 加载所需的DLL大约需要2秒。

加载完成后,如果再次关闭window再调用,会立即调用

它被认为是加载与 DevExpress 控件相关的 DLL 所花费的时间。

我通过Nuget安装了DevExpress相关包。 当程序是运行?

时,有没有办法预加载所有需要的包相关的DLL

您可以 运行 为特定程序集中的类型启动静态初始化程序。尽管您可能想在后台线程中启动它。

foreach (var a in
    AppDomain.CurrentDomain.GetAssemblies()
        .Where(a => a.GetCustomAttribute<AssemblyCompanyAttribute>()?.Company == /* todo */ )
    )
{
    foreach (var t in a.GetTypes())
        RuntimeHelpers.RunClassConstructor(t.TypeHandle);
}

但是可能会有进一步的惰性初始化来加速这些 DevExpress 控件。

有点。首先请注意程序集加载和 JIT 是在第一次调用时发生的,因此加载程序集只是工作的一部分。

您可以构建单个文件应用程序https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file and optionally use Ahead-of-time compilation https://docs.microsoft.com/en-us/dotnet/core/deploying/ready-to-run