Search code examples
c#ilmerge

How to compile all files to one exe?


I wrote a project in C# that uses a lot of images, Milk models and openGL and i want to pack everything in one exe so i can upload it to my site. Right now i got an exe that is depended on other files like jpgs etc'. I've tried using ILMerge but couldn't get it to work. Is there a simpler solution? thanks.


Solution

  • Add that as an embedded resource.

    Inside Visual Studio :

    1. Go to Solution Explorer,
    2. Right click the image,
    3. GO to Build Actions: Select Embedded Resource.

    You will have that image inside the exe. Later you can use Reflection and get the image when you run your application.

    ========= Getting the Embedded image from the Application =========

    First solve the first problem: by putting images as embedded resource.

    Second problem: Access the images by using Reflection:

    private void Form1_Load(System.Object sender, System.EventArgs e)
    {
        System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
        Stream myStream = myAssembly.GetManifestResourceStream("EmbeddingExample.image1.bmp");
        Bitmap image = new Bitmap(myStream);
    
        this.ClientSize = new Size(image.Width, image.Height);
    
        PictureBox pb = new PictureBox();
        pb.Image = image;
        pb.Dock = DockStyle.Fill;
        this.Controls.Add(pb);
    }
    

    Borrowed Source Code from here: