How to embed all files in a folder as resources

B

Bob Altman

Hi all,

I have a folder on my disk that contains a bunch of files. Elsewhere on my
disk I have a VB application that wants to embed those files as resources
when it is compiled. The trick is, the files in the folder can change over
time, so I need some sort of automatic way of embedding *all* of the files
in that folder into my application. (I really don't want to have to modify
the VB project when a file is added or removed from the folder -- I want the
build step to figure it out on its own.)

Can this be done?

TIA - Bob
 
T

Tom Shelton

Hi all,

I have a folder on my disk that contains a bunch of files. Elsewhere on my
disk I have a VB application that wants to embed those files as resources
when it is compiled. The trick is, the files in the folder can change over
time, so I need some sort of automatic way of embedding *all* of the files
in that folder into my application. (I really don't want to have to modify
the VB project when a file is added or removed from the folder -- I want the
build step to figure it out on its own.)

Can this be done?

TIA - Bob

Add the files to your project using Project->Add Existing Item. If you
planning to maintain these files in a different directory then your project,
then you'll want to probably change the default Add to Add As Link.

Then, once the file is added ot your project - then in solution explorer,
change the files Build Action to Embeded Resource. This will cause the file
to be embeded when you compile.

To access the resource, you can write code something like (we'll assume this
is a bitmap image):

' The YourAppName is required, but the ProjectSubFolder isn't necessary if you
' added the file to the projects root directory...
Using (imgStream As Stream = _
Assembly.GetExecutingAssembly.GetManifestResourceStream("YourAppName.ProjectSubFolder.BitMap01.bmp"))
pictureBox1.Image = New Bitmap(imgStream)
End Using

Anyway - something like that :) That's just aircode, so you might need to
adjust...
 
B

Bob Altman

Add the files to your project using Project->Add Existing Item. If you
planning to maintain these files in a different directory then your
project,
then you'll want to probably change the default Add to Add As Link.

Then, once the file is added ot your project - then in solution explorer,
change the files Build Action to Embeded Resource. This will cause the
file
to be embeded when you compile.
<snip>

Tom Shelton

Thanks Tom. As I said in the original posting, the set of files that must
be included is likely to change, and I don't want to have to revisit this
code each time a file is added or removed from the magic folder. I'm
looking for a way to have all of the files in that folder embedded as
resources, not just a set of files that I statically linked to in my
project.

Bob
 
T

Tom Shelton

Thanks Tom. As I said in the original posting, the set of files that must
be included is likely to change, and I don't want to have to revisit this
code each time a file is added or removed from the magic folder. I'm
looking for a way to have all of the files in that folder embedded as
resources, not just a set of files that I statically linked to in my
project.

Bob

So, it sounds like your looking for something more "dyanmic"... I think you
could probably accomplish this with an MSBuild script. But, it would take a
little playing around (at least for me ).
 
H

Hongye Sun [MSFT]

Thanks for Tom's help.

Hi Bob,

Regarding embedding resources under one specific folder, here is one way to
do it.

1. In Visual Studio, right click the project in solution explorer, unload
project
2. Right click the unloaded project and select Edit project file
3. Add the following target code snippet into vbproj file:
<Target Name="BeforeBuild">
<ItemGroup>
<EmbeddedResource Include="<Folder Path>\*.*">
</EmbeddedResource>
</ItemGroup>
</Target>
Please replace "Folder Path" into physical disk path.
4. Save and reload the project.

When building, Visual Studio will automatically build all the files under
the specific folder as embeded resouce of the assembly.

Please let me know if it works for you. Thanks.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within?2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Tom Shelton

Thanks for Tom's help.

Hi Bob,

Regarding embedding resources under one specific folder, here is one way to
do it.

1. In Visual Studio, right click the project in solution explorer, unload
project
2. Right click the unloaded project and select Edit project file
3. Add the following target code snippet into vbproj file:
<Target Name="BeforeBuild">
<ItemGroup>
<EmbeddedResource Include="<Folder Path>\*.*">
</EmbeddedResource>
</ItemGroup>
</Target>
Please replace "Folder Path" into physical disk path.
4. Save and reload the project.

Ahh... I knew you could do it with msbuild (VS project files are just msbuild
scripts...)
 
H

Hongye Sun [MSFT]

Yes, Tom.

We can directly build vbproj or csproj by msbuild command line:

msbuild /property:Configuration=Release|Debug <File.vbproj | csproj>

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
H

Hongye Sun [MSFT]

You are welcome, Bob. It is my pleasure to work with you.

Thanks for using our Microsoft Newsgroup Service.

Have a nice day.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top