如何在Assembly.LoadFile()之前从DLL读取属性

Zig*_* Ho 6 c# dll .net-assembly

我的程序有一个pluginManager模块,它可以加载DLL文件并运行DLL的方法,但我需要先阅读DLL属性Assembly.LoadFile().我该怎么办?

我读了关于Assembly文档,他们读了属性之后Assembly.LoadFile(),你知道Assembly没有UnLoad()方法,所以我必须在LoadFile()之前读取属性 在此输入图像描述

    private void ImprotZip(string path)
    {
        /*
        1?create tempDir, uppackage to tempDir
        2?Load Plugin DLL, Load plugin dependent lib DLL
        */
        string tempDirectory = CreateRuntimeDirectory(path);
        string[] dllFiles = Directory.GetFiles(tempDirectory);
        ///Load DlL
        foreach(string dll in dllFiles)
        {
            ImprotDll(dll, false);
        }
        string libPath = string.Format("{0}\\lib\\", tempDirectory);
        if (!Directory.Exists(libPath))
            return;
        string[] dlls = Directory.GetFiles(libPath);
        ///Load plugin dependent lib DLL
        foreach(string dll in dlls)
        {
            try
            {
                //filtering same DLL 
                //if(Dll.properties.AssemblyProduct != "something")
                //continue;
                Assembly.LoadFile(dll);
            }
            catch(Exception e)
            {
                e.Log();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

Mic*_*ter 1

FileVersionInfo.GetVersionInfo正是您正在寻找的。