Question

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.

Was it helpful?

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:

OTHER TIPS

You can put all your files/images into the exe as Embedded Resources.

See How to embed and access resources by using Visual C# (This link currently 404s)

ilmerge is only for merging .net CLR binaries together, usually for bundling libraries into your main executable.

For things like art assets, you want to embed them as resources into your application. From a resource you can get a stream which lets you work with the data as if it were in a file.

See this MSDN article for information on embedding resources: http://support.microsoft.com/kb/319292

When you add an image to the project in properties you can set it as Embedded Resource, then it'll be added to the binary file (dll or exe)

I shall prefer to create a satellite assembly for resource files. http://msdn.microsoft.com/en-us/library/21a15yht%28v=vs.71%29.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top