简体   繁体   中英

Copy Resource icon on dll load

I have a C# assembly with a resource file that contains an icon. How can I copy the resource on every load to the caller directory. When i compile the assembly it copies fine...but I need to copy on every load of the assembly so the calling executable can use it.(The resource folder gets deleted when the executable unloads)

You could embed the resource file and the write it out every time the assembly is loaded. Set the resource file to have a "Build Action" equal to "Embedded Resource" in the file properties of the visual studio solution explorer.

then you can unpack it with something like this:

        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);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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