printinguwpbackground-taskappxmanifest

How to register for the PSA printing background task


I'm working on PSA (Print Support App) development with the following environment: Windows 10 22H2 and Windows 11 SDK 10.0.26100.0.

In the appx manifest, I attempted to register a background task using the following code snippet:

<printsupport:Extension Category="windows.printSupportWorkflow" EntryPoint="PtBackgroundTask.PrintSupportBackgroundTask" uap11:SupportsMultipleInstances="true" />

I confirmed that the namespace is properly declared, but the compilation fails with the error: "The Appx package manifest is invalid." The project compiles successfully only after commenting out this line.

After researching, I found that the following alternative registration methods compile without issues which is under the uap4 framework,category is "windows.printWorkflowBackgroundTask"

<uap4:Extension Category="windows.printWorkflowBackgroundTask" EntryPoint="PtBackgroundTask.PrintSupportBackgroundTask" 
uap11:SupportsMultipleInstances="true"/>

The following is the appx manifest file and code for the background registration task.

appx manifest file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<Package
    xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
    xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
    xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
    xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
    xmlns:uap11="http://schemas.microsoft.com/appx/manifest/uap/windows10/11"
    xmlns:printsupport="http://schemas.microsoft.com/appx/manifest/printsupport/windows10"
    IgnorableNamespaces="uap uap4 uap11 mp printsupport">

    <Identity
      Name="9fc6b82c-561e-4f3d-8514-d6445f2049d8"
      Publisher="CN=Admin"
      Version="1.0.0.0"/>

    <mp:PhoneIdentity PhoneProductId="9fc6b82c-561e-4f3d-8514-d6445f2049d8" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

    <Properties>
        <DisplayName>PsaSampleApp</DisplayName>
        <PublisherDisplayName>PsaSample Document Solutions Inc</PublisherDisplayName>
        <Logo>Assets\StoreLogo.png</Logo>
    </Properties>

    <Dependencies>
        <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.26100.0" />
        <PackageDependency Name="Microsoft.UI.Xaml.2.8" MinVersion="8.2310.30001.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
        <PackageDependency Name="Microsoft.NET.Native.Framework.2.2" MinVersion="2.2.29512.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
        <PackageDependency Name="Microsoft.NET.Native.Runtime.2.2" MinVersion="2.2.28604.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
        <PackageDependency Name="Microsoft.VCLibs.140.00" MinVersion="14.0.33519.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
        <PackageDependency Name="Microsoft.Services.Store.Engagement" MinVersion="10.0.23012.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
        <PackageDependency Name="Microsoft.VCLibs.140.00.UWPDesktop" MinVersion="14.0.33728.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
        <PackageDependency Name="Microsoft.VCLibs.140.00.Debug" MinVersion="14.0.33519.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
    </Dependencies>

    <Resources>
        <Resource Language="EN-US" />
        <Resource uap:Scale="200" />
    </Resources>

    <Applications>
        <Application Id="App"
          Executable="$targetnametoken$.exe"
          EntryPoint="PsaSampleApp.App">
            <uap:VisualElements
              DisplayName="PsaSampleApp"
              Square150x150Logo="Assets\Square150x150Logo.png"
              Square44x44Logo="Assets\Square44x44Logo.png"
              Description="PsaSampleApp"
              BackgroundColor="transparent">
                <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
                <uap:SplashScreen Image="Assets\SplashScreen.png" />
            </uap:VisualElements>

            <Extensions>
                <uap:Extension Category="windows.printTaskSettings" Executable="PsaSampleApp.exe" EntryPoint="PsaSampleApp.App" uap11:SupportsMultipleInstances="true"/>
                <printsupport:Extension Category="windows.printSupportSettingsUI" EntryPoint="PsaSampleApp.App" uap11:SupportsMultipleInstances="true"/>
                <printsupport:Extension Category="windows.printSupportJobUI" EntryPoint="PsaSampleApp.App" uap11:SupportsMultipleInstances="true"/>
                <!--<uap4:Extension Category="windows.printWorkflowBackgroundTask" EntryPoint="PtBackgroundTask.PrintSupportBackgroundTask" uap11:SupportsMultipleInstances="true"/>-->
                <printsupport:Extension Category="windows.printSupportWorkflow" EntryPoint="PtBackgroundTask.PrintSupportBackgroundTask" uap11:SupportsMultipleInstances="true" />          </Extensions>
        </Application>
    </Applications>

    <Capabilities>
        <Capability Name="internetClient" />
    </Capabilities>
</Package>

PtBackgroundTask:

namespace PtBackgroundTask
{
    public sealed class PrintSupportBackgroundTask : IBackgroundTask
    {
        private BackgroundTaskDeferral taskDeferral;
        private PrintSupportExtensionSession session;
        private IppPrintDevice ippPrintDevice;

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("### PrintSupportBackgroundTask is running ###");

            // 获取任务延迟对象
            taskDeferral = taskInstance.GetDeferral();
            taskInstance.Canceled += OnTaskCanceled;

            // 获取打印支持扩展触发详情
            var triggerDetails = taskInstance.TriggerDetails as PrintSupportExtensionTriggerDetails;
            if (triggerDetails == null)
            {
                Debug.WriteLine("Error: invalid triggerDetails..");
                taskDeferral.Complete();
                return;
            }

            // 获取打印会话
            session = triggerDetails.Session as PrintSupportExtensionSession;
            if (session == null)
            {
                Debug.WriteLine("Error: get session fail..");
                taskDeferral.Complete();
                return;
            }
        }
    }
}

What are the differences between these registration methods? How should I correct the error to use the printsupport method successfully?


Solution

  • I confirmed that the namespace is properly declared, but the compilation fails with the error: "The Appx package manifest is invalid.

    You need to refer this doc first, Your problem is uap11:SupportsMultipleInstances="true" is not Extension property, it is Application property. And then I will post the complete Package.appxmanifest file as reference below for you.

    <?xml version="1.0" encoding="utf-8"?>
    <Package 
      xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
      xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
      xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
      xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4" 
      xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2" 
      xmlns:printsupport="http://schemas.microsoft.com/appx/manifest/printsupport/windows10" 
      IgnorableNamespaces="uap mp">
      
      <Identity
        Name="b65f4916-9199-46a3-8d41-f95fa5ca4dcd"
        Publisher="CN=U59166"
        Version="1.0.0.0" />
    
      <mp:PhoneIdentity PhoneProductId="b65f4916-9199-46a3-8d41-f95fa5ca4dcd" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
    
      <Properties>
        <DisplayName>PrintApp</DisplayName>
        <PublisherDisplayName>U59166</PublisherDisplayName>
        <Logo>Assets\StoreLogo.png</Logo>
      </Properties>
    
      <Dependencies>
        <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
      </Dependencies>
    
      <Resources>
        <Resource Language="x-generate"/>
      </Resources>
    
      <Applications>
        <Application Id="App"
                     desktop4:SupportsMultipleInstances="true"
                     iot2:SupportsMultipleInstances="true"
          Executable="$targetnametoken$.exe"
          EntryPoint="PrintApp.App">
          <uap:VisualElements
            DisplayName="PrintApp"
            Square150x150Logo="Assets\Square150x150Logo.png"
            Square44x44Logo="Assets\Square44x44Logo.png"
            Description="PrintApp"
            BackgroundColor="transparent">
            <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
            <uap:SplashScreen Image="Assets\SplashScreen.png" />
          </uap:VisualElements>
          <Extensions>
            <printsupport:Extension  Category="windows.printSupportWorkflow"   
                EntryPoint="PsaBackgroundTasks.PrintSupportWorkflowSample" />
          </Extensions>
        </Application>
        
      </Applications>
      <Capabilities>
        <Capability Name="internetClient" />
      </Capabilities>
    
    </Package>