Cannot add USB DeviceCapability in WinUI 3 App Package.appxmanifest

rhubarb.geek.nz 61 Reputation points
2022-06-04T08:11:10.35+00:00

I have a UWP app that I am porting to WinUI 3

I want to specify the restricted set of capability so it can be published in the app store.

I am unable to add a USB DeviceCapability

The error I get is during the packaging phase saying the manifest conflicts with the schema.

https://sourceforge.net/p/myfeeder/code/HEAD/tree/trunk/winui3/MyFeeder/Package.appxmanifest

I want it to look like the following which works with UWP

<Capabilities>
<Capability Name="internetClient" />
<uap:Capability Name="sharedUserCertificates" />
<DeviceCapability Name="usb">
<Device Id="vidpid:04cc 0531">
<Function Type="classId:ff * *" />
</Device>
</DeviceCapability>
</Capabilities>

I can only build by commenting out the DeviceCapability, and it works because a local install of a WinUI 3 app seems to assume <rescap:Capability Name="runFullTrust" />

I have tried re-ordering and using different namespaces, but it seems like the conflict is the DeviceCapability.

Any suggestions?

Thanks.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
743 questions
0 comments No comments
{count} vote

Accepted answer
  1. Xiaopo Yang - MSFT 12,071 Reputation points Microsoft Vendor
    2022-06-09T01:53:06.68+00:00

    Hello, @rhubarb.geek.nz

    It seems there’s an issue with the Single-project MSIX Packaging Tools, or with some part of VS that only surfaces when packaging in the same project. When using the single-project format, the AppxManifest.xml generated will have the runFullTrust re-added to the capabilities list. It’s also added in the wrong order per the schema, so that new AppxManifest fails validation, hence the manifest vs schema error we’re seeing.

    Splitting the project referenced (myfeeder / Code / [r47] /trunk/winui3/MyFeeder (sourceforge . net)) into separate packaging and base projects allowed me to get it to build without issue. In addition, the separate packaging project does not re-add the runFullTrust capability, so you can see the Low Mandatory Level integrity flag, indicating we’re at partial trust. You can read more about partial trust and WinUI 3 here: https://github.com/microsoft/WindowsAppSDK/discussions/1900#discussioncomment-1791826

    To split, the you can basically go through the Package your app using single-project MSIX - Windows apps | Microsoft Learn article backwards. Leaving the launchSettings.json or Package.appxmanifest files doesn’t hurt anything so you can keep those in the project. The only real change to the original project is the commenting of two XML nodes.

    1. Double-click the MyFeeder project.
    2. Comment out / remove:
      oEnablePreviewMsixTooling
      oPublishProfile
    3. Add a new project to the solution using the “Windows Application Packaging Project” template.
    4. Set the new project as the startup project.
    5. Add a project reference to the MyFeeder project.
      oExpand the new project -> Dependencies -> Applications
      oSelect MyFeeder
      oSet the Trust Level to “Partial Trust”
    6. Replace the Package.appxmanifest with the one from the MyFeeder project.

    That should resolve the issue for now.

    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. rhubarb.geek.nz 61 Reputation points
    2022-06-09T06:12:06.207+00:00

    Hi,

    I am going to abandon this until we have proper support in Visual Studio. The changes I am making are chasing schema errors and versions errors that I have no hope of resolving. I don't want to spend time my fighting Visual Studio when it should be solving the problems.

    Thanks for identifying the problem lies in the toolset, I will wait until they are fixed.

    Thanks again.

    1 person found this answer helpful.

  2. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,861 Reputation points
    2022-06-06T02:58:25.94+00:00

    Hello,
    Welcome to Microsoft Q&A!

    Cannot add USB DeviceCapability in WinUI 3 App Package.appxmanifest

    It should be VS problem that contains rescap capability, please try to reorder the capabilities and place runFullTrust first line and place DeviceCapability at the end . I have tested the following, it could work well in WinUI 3 project.

    <rescap:Capability Name="runFullTrust" />  
      
    <Capability Name="internetClient" />  
    <uap:Capability Name="sharedUserCertificates" />  
      
    <DeviceCapability Name="usb">  
      <Device Id="vidpid:04cc 0531">  
        <Function Type="classId:ff * *"/>  
      </Device>  
    </DeviceCapability>  
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. rhubarb.geek.nz 61 Reputation points
    2022-06-11T09:11:43.007+00:00

    I had another and found something out, but I don't know if it is what is supposed to happen.

    My expectation of creating an x64 package is that it would only create an x64. But that is not the case.

    I created 3 different solutions each with the application project and packaging project. Each solution was for a different architecture. I remove all references to "Any CPU" or a foreign architecture for each solution, so arm64 only contained references to arm64, x64 only to x64, and x86 only to x86.

    What I found was that only the x86 would build.

    Both the ARM64 and x64 both built the application but failed with the packaging due to

    MyFeeder\obj\wappublish\win-x86\project.assets.json

    Copying the win-x64 over the win-x86 directory does not work because it really wants the x86 version.

    So the end result is you cannot package a pure arm64 or x64 package, as both seem intent on referencing x86.

    0 comments No comments

  4. rhubarb.geek.nz 61 Reputation points
    2022-06-11T09:50:53.743+00:00

    Hi, @Xiaopo Yang - MSFT

    Thank you for your patience, I think we have found another part of the fix.

    With my individually targeted solutions I can now build unique x86, x64 and arm64 msix

    In the original MyFeeder.csproj you have to change

    -    <PlatformTarget>AnyCPU</PlatformTarget>  
    +    <PlatformTarget>x64</PlatformTarget>  
    

    In addition to

    -    <AppxBundlePlatforms>x86|x64|arm64</AppxBundlePlatforms>  
    +    <AppxBundlePlatforms>x64</AppxBundlePlatforms>  
    

    So now I do finally have an x64 msix of a WinUI3 with limited permissions like a UWP

    Thank you again for your assistance.

    0 comments No comments