簡體   English   中英

DLL加載時復制資源圖標

[英]Copy Resource icon on dll load

我有一個C#程序集,其資源文件包含一個圖標。 如何在每次加載時將資源復制到調用者目錄。 當我編譯程序集時,它可以很好地復制...但是我需要在程序集的每次加載時都進行復制,以便調用的可執行文件可以使用它。(當可執行文件卸載時,資源文件夾將被刪除)

您可以嵌入資源文件,並在每次加載程序集時將其寫出。 在Visual Studio解決方案資源管理器的文件屬性中,將資源文件設置為具有等於“嵌入式資源”的“生成操作”。

那么您可以使用以下內容將其解壓縮:

        private static string _srvExePath;
        private static void UnpackFiles()
        {
            if (!Directory.Exists(_srvExePath))
            {
                Directory.CreateDirectory(_srvExePath);
            }

            Stream s1 = Assembly.GetExecutingAssembly().GetManifestResourceStream( assmblyname +"."+ resourcefile);
            byte[] b1 = new byte[s1.Length];
            s1.Read(b1, 0, (int)s1.Length);

            File.WriteAllBytes(_srvExePath + file, b1);
            //Console.WriteLine("unpacking: " + _srvExePath + file);
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM