Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between a Resource and an Embedded Resource in a C# application?

When should I use one or the other?

I'd like all of the files I use in my app (images, sound, xml file, etc.) to be inside of the .exe file so I don't deploy with a bunch of folders and files.

Thanks for the info.

like image 909
Sergio Tapia Avatar asked Dec 20 '09 04:12

Sergio Tapia


People also ask

What is an embedded resource?

Embedded resource has no predefined structure: it is just a named blob of bytes. So called “. resx” file is a special kind of embedded resource. It is a string -to-object dictionary that maps a name to an object. The object may be a string , an image, an icon, or a blob of bytes.

How do I add embedded resources to Visual Studio?

Open Solution Explorer add files you want to embed. Right click on the files then click on Properties . In Properties window and change Build Action to Embedded Resource . After that you should write the embedded resources to file in order to be able to run it.

How do you change a build action to an embedded resource?

Click in the solution explorer the file that will be modified. Then hit F4 or click with the right button in the file and then select the "Properties" option. In the Properties window, change Build Action to Embedded Resource.


2 Answers

“Resource” and “Content” build actions are to access the WPF resources using the Uris. However “Embedded Resource” is for prior technologies. However both options embed the resource in assembly but “Resource” option to be used for WPF.

MSDN provides full explanation here.

like image 153
viky Avatar answered Sep 28 '22 03:09

viky


A WPF resource (build action = Resource) leverages embedded resources as supported by the core .NET framework, but adds support for accessing the embedded resource via a pack URI. From MSDN:

WPF resource files are not the same as the embedded or linked type of resources that can be configured using the core .NET Framework support for assembly resources. While WPF resource files do leverage the core .NET Framework embedded resource support, the ability to access WPF resource files using pack URIs is easier than using namespaces.

like image 44
Kent Boogaart Avatar answered Sep 28 '22 04:09

Kent Boogaart