How can I bundle all files in a folder into UWP application package in VS2015?

Viewed 584

I have a UWP app that includes a webview that shows files compiled from a separate source. The separate source dumps all the files out into a folder, and I want to just include the entire contents of that folder automatically in my UWP build.

I've not found a simple, automatic way to do this.

I can sloggingly add them manually using this method: Copying assets into UWP application package however this doesn't really help me because the process that generates the files in the folder can add, remove or change the names of the files all over the place. Every time it does this (and this can be multiple times a day) I have to go in and re-add or remove the files that have appeared/disappeared.

Currently my best idea is to write a script that will parse the folder, list the files and then automatically generate a vcxproj file from that list. This, however, seems hacky and would have several drawbacks (eg. any changes I make to the project file in VS2015 would get binned unless I also changed the script)

Is there a way to just tell VS2015 to put all the files (and sub-folders) in a named folder into the UWP app, no questions asked?

1 Answers

It's possible to add a folder and all subfolders and files via a Property Sheet/.props file.

This example includes all files and the folder structure below 'TestItem' in the UWP appx package under 'Assets\Website'. Note that there's no entry for TestItem itself, as that is the root.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />

  <ItemGroup>
    <_CustomResource Include="..\..\TestItem\**\*">
      <Link>Assets\Website\%(RecursiveDir)%(FileName)%(Extension)</Link>
      <DeploymentContent>true</DeploymentContent>
    </_CustomResource>
  </ItemGroup>

  <Target Name="_CollectCustomResources" BeforeTargets="AssignTargetPaths">
    <Message Text="Adding resource: %(_CustomResource.Identity) -&gt; %(_CustomResource.Link)" />
    <ItemGroup>
      <None Include="@(_CustomResource)" />
    </ItemGroup>
  </Target>
</Project>

The Property Manager can be used to add new Property Sheets to a project.
Note that I didn't find any way in the IDE to add, edit or even view the above properties, so I made the .props file by hand.

Related