Unsure how to embed resources in a hierarchical way

  • Thread starter Thread starter Andy_B
  • Start date Start date
A

Andy_B

Guest
I am working with a desktop forms application in Visual Studio 2019, written in VB.net
Part of the application operates as a web-server.

Currently, the web-server serves files from a 'Webroot' folder in the file system.
Many of the files are organized nicely into subfolders below the Webroot for lib, css, script, images etc...

Having these files in the file system is great for development but I now need to embed them as resources in a release executable to make the application more resilient against tampering.

I have dragged the Webroot folder structure into my project and set the build action on all the files to 'Embedded Resource'.

I want to be able to access the files as resources in a similarly hierarchical way, by code like:
Dim Target = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("Webroot.js.lib.jquery-3.2.1.min.js)

ISSUE:
My problem is that the compiler seems to be flattening the folder structure, putting all embedded resource files at the same level i.e. the file in the example above could only be loaded by:
Dim Target = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream("jquery-3.2.1.min.js").


I first saw this issue because our web designer had accidentally left copies of the same file in two sub-folders and the compiler gave error:
"Error BC31502 Resource name 'Crimp_Centre.ajax-loader.gif' cannot be used more than once."

It is easy to repro the issue if necessary.
REPRO:
In VS2019
File..New Project then use template {Windows Forms App (.NET Framework) Desktop, Visual Basic, Windows }
In Solution Explorer:
Rt-click the project node and Add..New Folder. It should appear with default name NewFolder1
Rt-click NewFolder1 and Add..New Folder. It should appear with default name NewFolder1. Rename it SubFolder1 to make things less confusing.
Rt-Click SubFolder1 and Add..New Item. {General.. Text File}. It should create a file 'TextFile1.txt'.
Click TextFile1.txt and (in properties window) change its Build Action to 'Embedded Resource'
At this point the project will compile and run.
Rt-Click NewFolder1 and Add..New Item. {General.. Text File}. It should create a file 'TextFile1.txt'.
Click on the newly created TextFile1.txt and (in properties window) change its Build Action to 'Embedded Resource'
We now have identically named files at different levels in the resource folder structure.
Attempting to compile produces Error "BC31502 Resource name 'WindowsApp1.TextFile1.txt' cannot be used more than once."

QUESTION:
Please can anyone show me how to embed resources in a hierarchical way, I would like to mirror the folder structure we have in the file system?
I understand embedded resources can be stored and referenced hierarchically in a C# project but my project has tens of thousands of lines of VB code and I have practically no chance of rewriting it in C#.
I suspect there could be a compiler switch needs changing but I cannot see it.

Continue reading...
 
Back
Top