106

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.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Sergio Tapia
  • 40,006
  • 76
  • 183
  • 254

4 Answers4

95

“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.

Saikat
  • 14,222
  • 20
  • 104
  • 125
viky
  • 17,275
  • 13
  • 71
  • 90
  • 1
    You're right! I set all the images in my WPF project to Resource and re-built the source. Now when I navigate to the Debug folder I cannot find the files anywhere, they must be a part of the .exe, exactly how I want it. Can't thank you enough! :) – Sergio Tapia Dec 20 '09 at 13:48
  • 4
    The MSDN link is broken. Additional explanation here would be very nice. – Michael Harris May 24 '18 at 17:49
13

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.

Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
4

As reported by MSDN,

Embedded resources are the best choice if you have to share application resource (.resx) files between multiple projects. For example, if you have a common resource file that contains your company's logos, trademark information, and such, using embedded resources means you have to copy only the .resx file and not the associated resource data files.

You cannot edit embedded resources directly. If you try to edit an embedded resource, you will receive a message prompting you to convert the item to a linked resource in order to edit it. Conversion is recommended but optional. You must export them, make your modifications in an external program, and then import them back into your project.

apaderno
  • 28,547
  • 16
  • 75
  • 90
  • 5
    This diesn't answer the question: what is the difference between an embedded resource and a resource? You answer only addresses Embedded Resources. – Grokys Dec 20 '09 at 04:51
  • 4
    The text of the question says "When should I use one or the other?"; I think I answered to that. The questions are really two. – apaderno Dec 20 '09 at 22:11
1

Thanks for all the reports, that helped me find more precisely where was the problem: For me, it was the images used as project icon in the task bar that was built as resources and had to be built as content. All others images can be build as resources, no problem.

Hope this helps for the future.

Piyush
  • 18,895
  • 5
  • 32
  • 63