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).

2
  • Maybe you can copy the folder with a pre build event. The following article may help you: stackoverflow.com/questions/12577496/… Commented Nov 19, 2015 at 9: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. Commented Nov 19, 2015 at 17:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.