wpcoder
wpcoder

Reputation: 1054

vb.net linked vs embedded resources weird result - VS 2017 CE

This suppose to be a simple issue; not to be posted as a question in stack overflow!

Following this article: How to: Create Embedded Resources

  1. I had created a new and fresh Form1.vb to test in Visual Studio 2017 community edition.
  2. Added a big testfile.WAV file as a test resource.
  3. Checked the link type is set to default value: "Linked at compile time" Default Value.
  4. Clean/Build/Rebuild the application.


Looks very weird to me? is it a bug in VS or in app setting?

Thank you so much Appreciated any hint

Note: What I was trying to reach is to create a different themes for my application, where users can chose the appearance; and my efforts break in the above scenario. It doesn't make sense that result.exe ends in 10s of MB if it will include resources inside it!

Upvotes: 1

Views: 636

Answers (1)

Visual Vincent
Visual Vincent

Reputation: 18310

TL;DR: If you want it as a loose file then you need to have it as a loose file. Resources are always embedded in the application.

If you add the resource via Project Properties > Resources then it will always be embedded in your application.

If you want it as a loose file then you shall just import it to your project via Add Existing Item and set the Copy to Output Directory property of the item to Copy Always. Then you reference it by doing for example:

Dim WavPath As String = Path.Combine(Application.StartupPath, "yourfile.wav")
Dim WavFile As Byte() = File.ReadAllBytes(WavPath)

Linked vs Embedded only make a difference at design time. Linked resources are still embedded in your application, but at design time you may edit them and can easily add or remove other resources.

Embedded resources however are embedded in a .resx file even at design time, and to edit such resources you have to export them or change them into a linked resource. Embedded resources are mostly used when you need to share the same resources in multiple projects. The resources are then embedded in the .resx file so you only need to copy that and not every included file.

Upvotes: 1

Related Questions