Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Build Action: Difference between None and Embedded Resource?

I use pictures over some of my buttons and I don't want these images included in the output.

These images are set through the buttons properties, so they are defined in the Resource.resx file.

I was told to set the Build Action to Embedded Resource, but I'm curious as to why this makes a difference. I have the build action set to "None" right now, and none of the files are set to copy. And I can move the built application anywhere and launch it and all the images show just fine. (Just to clarify, the images are definitely not in the directory of the program when it's launching, and they still appear just fine).

I looked it up on the MSDN and got this:

None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.

Embedded Resource - This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files.

But from this is sounds like having them all set at None shouldn't even be working (but it does).

So I'm curious as to what benefit setting it to Embedded Resource gives. I did test it out, and there was no difference. Was hoping someone could explain what's happening.

My only assumption is that when setting the image property through the button and the entry gets added to the resource file, it's in no way connected to the file added to the project (even though they're the same). So if you're setting the image property this way, do the images not even need to be included in the project (i.e. in the solution explorer).

Thank you!

like image 496
Wrightboy Avatar asked Feb 26 '13 18:02

Wrightboy


1 Answers

It seems you have stumbled over two different ways of displaying an image.

  1. If you use a resource file then the resource file itself will contain the images and that file will be copied into the output directory. You will then reference the image out of this resource file and all will be well. The actual image setting for none/embedded/content will not matter. This allows you to create resource files for a variety of languages and locations and change which image is used based on your applications culture.

  2. The other way to reference an image is by either embedding it or setting it as content in the project. If you set it as content it will copy to the output directory and can be referenced physically based on location or if you embed it the file will be located inside the dll that is created and you can pull a resource stream with that file in it using built in functions.

You are using method #1 so once you have put it in the resource file you don't have to have it in the project since the resource file is in the project already and that is where the file will come from.

like image 126
Bryan Roberts Avatar answered Oct 03 '22 02:10

Bryan Roberts