Search code examples
xamlunity-game-engineuwphololens

Add broadFileSystemAccess capability to Unity+UWP


I am trying to add the capability named broadFileSystemAccess to our UWP application that is built with Unity and has no XAML markup. The documentation says to add the following to the app manifest, but no app manifest exists in the unity / visual studio project. Is this capability not possible on MRP, or are we doing something wrong?

This is what is supposed to be added to your App package manifest, but like I mentioned, we don't have one of those.

<?xml version="1.0" encoding="utf-8"?>
<Package
    ...
    xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4">
...
<Capabilities>
    <uap4:CustomCapability Name="CompanyName.customCapabilityName_PublisherID"/>
</Capabilities>
</Package>

Solution

  • You can add capabilities as follows: PlayerSettingsWSA Capabilities

    If a capability is not in the list you must build your project with IL2CPP in order to output an app package manifest named Package.appxmanifest and modify the XML by yourself.

    In order to make things magically

    You can write a method which have a PostProcessBuildAttribute attibute like so: Unity - Scripting API: PostProcessBuildAttribute that will verify and add the XML tag if it not present in the Package.appxmanifest.

    Also you can create your custom build like that: Unity - Manual: Build Player Pipeline and add the same logic to verify and add the capability (an XML tag)

    Pseudo code:

    using UnityEngine;
    using UnityEditor;
    using UnityEditor.Callbacks;
    
    public class MyBuildPostprocessor {
        [PostProcessBuildAttribute(1)]
        public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
             XmlDocument xmlDoc = new XmlDocument();
             xmlDoc.Load($"{pathToBuiltProject}/{PROJECT NAME HERE}/Package.appxmanifest");
             // Find if the `broadFileSystemAccess` capability exists
             // add `broadFileSystemAccess` capability
        }
    }