How to compile all files to one exe?

二次信任 提交于 2019-11-28 08:35:29

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:

logicnp

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!