Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically add all files from folder as embedded resource

Tags:

c#

msbuild

  1. We wrote small app in C#. It is "installer" that copy files - embedded resources - to some location.
  2. We created one batch file which copies latest versions of these files and build the solution using msbuild.exe.

The problem here is that if anyone want to add another file (or remove existing file) they have to do it manually through Visual Studio.
Is there some way how one can do this automatically?

Example:
I have folder embeddedResources and in there I have files a.txt and b.txt. Both set as Embedded resources. Is there some automatic way, how to add new file c.txt as Embedded resource if I copy it to the folder embeddedResources? Or how to successfully build the solution if I delete the file a.txt?

like image 547
Artholl Avatar asked Mar 18 '26 08:03

Artholl


1 Answers

Just add following ItemGroup into your .csproj:

<ItemGroup>
    <EmbeddedResource Include="embeddedResources/*.txt" />
</ItemGroup>

Every file in embeddedResources folder with .txt extension will be automatically set as embedded resource.

like image 159
Tomanek1 Avatar answered Mar 20 '26 00:03

Tomanek1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!