3

I have a folder of images I want to embed as resources into a WPF app built using Visual Studio 2015. How can I do this dynamically at build time so that the folder contents is copied as-is and the app can access the images using Uri("pack://application:,,,/Resources/" + path)?

To be precise, I do not want to add the images from the folder one by one to the project as the contents of the folder is not constant.

Ideally the folder itself would be embedded as a resource so that the URIs would be Uri("pack://application:,,,/Resources/" + "MyFolder/" + path).

Pol
  • 3,848
  • 1
  • 38
  • 55
  • Maybe you can copy the folder with a pre build event. The following article may help you: http://stackoverflow.com/questions/12577496/pre-build-event-copy-folder-and-its-subfolders-and-files-into-build-directory – FKutsche Nov 19 '15 at 09:54
  • Unless I missed something this is about copying a folder to the target build directory, not put its contents as resources inside the app. – Pol Nov 19 '15 at 17:35

1 Answers1

0

I eventually figured it out based on this other question: the solution is to manually edit the .csproj file using Notepad or equivalent and insert another group like this:

  <ItemGroup>
    <Resource Include="..\..\_App_\Resources\*">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Resource>
  </ItemGroup>

Then whenever you re-open the Visual Studio solution, it will show all files in that folder under the project in the explorer and copy them to the app as resources.

Unfortunately, it doesn't appear possible to put these files under their own folder in the app resources.

Community
  • 1
  • 1
Pol
  • 3,848
  • 1
  • 38
  • 55