0

I have a UWP project in Visual Studio (2015, c++) and I want to include an external folder tree of assets (e.g. images) so that when I run it in the emulator those files are available (similarly, when I build a final package I want the files with the package). The files aren't fixed (i.e. I may add/remove files at a later time)

In a regular desktop application I would simply use a post-build step and do an xcopy on the folder into the target directory. This, however, does not work for the UWP build. When I run in the emulator nothing is there (or even in the target directory).

Is there some way to add a build step to copy files (retaining directory structure) or even better a way to add an external folder reference to the project?

I know I am not the only one that does this. Most results in searches are irrelevant, others aren't dynamic, or rely on the files to be within the project's directory tree.

ajso
  • 73
  • 7

2 Answers2

1

Use AppxPackagePayload element in your .vcxproj file:

<AppxPackagePayload Include="PathToYourImage.jpg">
  <TargetPath>SubfolderInPackage\FileName.jpg</TargetPath>
</AppxPackagePayload>

Unfortunately, you'll need to reference every file your want to copy separately. I don't know if there is a way to do it for a directory.

Sunius
  • 2,789
  • 18
  • 30
  • Unfortunately adding individual files would be unmanageable. However your answer did give me a vector for a better search and I found this which is very similar to my question (but for 8.1 instead of 10): https://stackoverflow.com/questions/28610893/how-do-i-include-content-files-in-subdirectories-in-windows-8-1-phone Unfortunately it looks like building w/ makeappx is my only option (and I am still unclear if that will even work w/ the emulator). Thank-you though. – ajso Aug 10 '17 at 08:08
0

I have a UWP project in Visual Studio (2015, c++) and I want to include an external folder tree of assets (e.g. images) so that when I run it in the emulator those files are available (similarly, when I build a final package I want the files with the package). The files aren't fixed (i.e. I may add/remove files at a later time)

From your description, I think you want to mount an external folder for your uwp app. However, not all path can be accessed directly under current file access rules.

Access to other locations is available only through a broker process. This broker process runs with the user’s full privileges, and it can use these privileges on the app’s behalf for locations the app has requested via capabilities, locations requested by the user via file pickers, etc. The StorageItem encapsulates this brokerage procedure so the app doesn’t need to deal with it directly.

As Rob said that you can access to other locations with the user’s full privileges. For more you could refer to File access permissions official documentation.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • Unfortunately my explanation may not be clear enough. By include I meant a collection of files external to the project being included when packaging. Sunius's answer lead me to the following question which is basically what I was looking for (although not the way to achieve it the way I would prefer): https://stackoverflow.com/questions/28610893/how-do-i-include-content-files-in-subdirectories-in-windows-8-1-phone – ajso Aug 10 '17 at 08:16