Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PackageDeploymentManager with DeferRegistrationWhenPackagesAreInUse and DependencyPackages does not update on next app start #4827

Open
whiskhub opened this issue Oct 24, 2024 · 3 comments
Labels
area-Deployment Issues related to packaging, installation, runtime (e.g., SelfContained, Unpackaged)

Comments

@whiskhub
Copy link

Describe the bug

When trying to (self-)update a MSIX package PackageDeploymentManager.AddPackageByUriAsync() method and AddPackageOptions DeferRegistrationWhenPackagesAreInUse = true AND with some DependencyPackageUris added, the MSIX package will not be updated on the next app start. Instead, the old version is re-registered and the newly staged package is being deleted again.

If you don't add any DependencyPackageUris to the options, then the update works as expected. This is the crazy part and took me lots of hours to debug. The DependencyPackageUris can be any kind of URI, the package doesn't even need to depend on it.


According to the AppxLog, Started deployment RegisterByPackageFamilyName operation on a package with main parameter PackageManagerRegisterTest_ad8pwfkyh69vj is called. But this operation seems to choose the old version instead of the new one. The AppxLog is also attached below.

Linked is a GitHub repository to reproduce the issue. The repo contains source code, and also two self-signed MSIX packages together with the self-signed certificate for testing the update scenario. https://github.com/whiskhub/PackageManagerRegisterTest

Steps to reproduce the bug

Have a MSIX packaged app (e.g. WinUI 3) that can auto-update itself. The update code should look the following:

var packageDeploymentManager = PackageDeploymentManager.GetDefault();

var options = new AddPackageOptions();
options.DeferRegistrationWhenPackagesAreInUse = true;

options.DependencyPackageUris.Add(new Uri("https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx")); // !!! THIS IS THE OFFENDING LINE. REMOVE IT AND THE BUG DISAPPEARS

var uri = new Uri("filepath_to_updated_msix.msix");
var operation = packageDeploymentManager.AddPackageByUriAsync(uri, options);

Execute the self-update within the app. Close the app. Start the app again. See the opened app and verify the version number is still old.
Confirm with PowerShell Get-AppxLog that the deferred registration took place, but with with the old version instead of the new one:

Expand for AppxLog
2024-10-24 19:02:49       603          Started deployment RegisterByPackageFamilyName operation on a package with main parameter PackageManagerRegisterTest_ad8pwfkyh69vj and Options
                                       ForceTargetApplicationShutdownOption,SkipReregisterIfPackageStatusOk,ImmediatePriorityRequest and 0. See
                                       http://go.microsoft.com/fwlink/?LinkId=235160 for help diagnosing app deployment issues.
2024-10-24 19:02:49       10002        Creating Resiliency File
                                       C:\ProgramData\Microsoft\Windows\AppRepository\b11aecf4-f404-40fd-ad08-7c49d0ef4e96_S-1-5-21-2220047017-4043106817-3966502983-1002_66.rslc for
                                       Register Operation on Package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj.
2024-10-24 19:02:49       607          Deployment Register operation on package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj has been de-queued and is running for user SID
                                       S-1-5-21-2220047017-4043106817-3966502983-1002.
2024-10-24 19:02:49       854          Successfully added the following uri(s) to be processed:  C:\Program
                                       Files\WindowsApps\PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj\AppxManifest.xml.
2024-10-24 19:02:49       672          Package Microsoft.VCLibs.140.00.UWPDesktop_14.0.33321.0_x64__8wekyb3d8bbwe does not satisfy a dependency for package
                                       PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj. Reason: The package's version is lower than the required MinVersion.
2024-10-24 19:02:49       672          Package Microsoft.VCLibs.140.00.UWPDesktop_14.0.33519.0_x64__8wekyb3d8bbwe does not satisfy a dependency for package
                                       PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj. Reason: The package's version is lower than the required MinVersion.
2024-10-24 19:02:49       672          Package Microsoft.VCLibs.140.00.UWPDesktop_14.0.33519.0_x86__8wekyb3d8bbwe does not satisfy a dependency for package
                                       PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj. Reason: The package's version is lower than the required MinVersion.
2024-10-24 19:02:49       855          Finished resolving action lists. DeploymentRequest action lists: addPackageList: PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj
                                       destagePackageList: PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj.
2024-10-24 19:02:49       9643         0x0: TerminateApplications successful.
2024-10-24 19:02:49       9643         0x0: TerminateApplications successful.
2024-10-24 19:02:49       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x0, Set=0x20).
2024-10-24 19:02:49       9643         0x0: TerminateApplications successful.
2024-10-24 19:02:49       9643         0x0: TerminateApplications successful.
2024-10-24 19:02:49       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x0, Set=0x820).
2024-10-24 19:02:49       5507         PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj : C:\Program Files\WindowsApps\PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj\microsoft.s
                                       ystem.package.metadata\S-1-5-21-2220047017-4043106817-3966502983-1002-MergedResources-*.pri : No user-specific merged files found
2024-10-24 19:02:49       5507         PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj : C:\Program
                                       Files\WindowsApps\PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj\microsoft.system.package.metadata\Resources.????????.pri : No shared merged
                                       files found
2024-10-24 19:02:49       5507         PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj : C:\Program Files\WindowsApps\PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj\microsoft.s
                                       ystem.package.metadata\S-1-5-21-2220047017-4043106817-3966502983-1002-MergedResources-*.pri : No user-specific merged files found
2024-10-24 19:02:49       5507         PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj : C:\Program
                                       Files\WindowsApps\PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj\microsoft.system.package.metadata\Resources.????????.pri : No shared merged
                                       files found
2024-10-24 19:02:49       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x20, Set=0x0).
2024-10-24 19:02:49       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x20, Set=0x0).
2024-10-24 19:02:49       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x10000C00, Set=0x0).
2024-10-24 19:02:49       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x300, Set=0x0).
2024-10-24 19:02:49       400          Deployment Register operation with target volume C: on Package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj from:  (AppxManifest.xml)
                                       finished successfully.
2024-10-24 19:02:49       472          Moving package folder \\?\C:\Program Files\WindowsApps\PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj to \\?\C:\Program
                                       Files\WindowsApps\Deleted\PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj724d814e-a6da-4d14-afd4-1aefc1964cec. Result: 0x0.
2024-10-24 19:02:50       613          Performance summary of Deployment Register operation on Package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj:
                                       Overall time: 547 ms
                                       Gap: 16 ms
                                       Enqueue cost: 0 ms
                                       Dequeue delay: 31 ms
                                       Bundle processing cost: 0 ms
                                       Indexing cost: 16 ms
                                       Resolve dependency cost: 0 ms
                                       Check approval cost: 0 ms
                                       Evaluation cost: 15 ms
                                       Hardlinking evaluation cost: 0 ms
                                       Stage required cost: 0 ms
                                       Flushing and closing files cost: 0 ms
                                       Gap: 16 ms
                                       Machine register cost: 0 ms
                                       Stage user data cost: 0 ms
                                       Registration cost: 78 ms
                                       Gap: 16 ms
                                       Repository commit transaction cost: 250 ms
                                       Gap: 62 ms
                                       Data flush cost: 0 ms
                                       Post DeStage repository commit transaction cost: 47 ms
                                       Remaining cost: 0 ms

2024-10-24 19:02:38       604          Started deployment Add operation on a package with main parameter PackageManagerRegisterTest_1.0.1.0_x64_Debug.msix, dependency parameters
                                       Microsoft.VCLibs.x64.14.00.Desktop.appx and Options 0 and DeferRegistrationWhenPackagesAreInUse. See http://go.microsoft.com/fwlink/?LinkId=235160
                                       for help diagnosing app deployment issues.
2024-10-24 19:02:38       157          The app package signature was validated for core content of the app package published by CN=Contoso Software, O=Contoso Corporation, C=US. Payload
                                       won't be validated until the files are read.
2024-10-24 19:02:38       216          App manifest validation warning: Declared namespace http://schemas.microsoft.com/developer/appx/2015/build is inapplicable, it will be ignored during
                                       manifest processing.
2024-10-24 19:02:38       170          The streaming reader was created successfully for app package PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj.
2024-10-24 19:02:40       157          The app package signature was validated for core content of the app package published by CN=Microsoft Corporation, O=Microsoft Corporation,
                                       L=Redmond, S=Washington, C=US. Payload won't be validated until the files are read.
2024-10-24 19:02:40       216          App manifest validation warning: Declared namespace http://schemas.microsoft.com/developer/appx/2015/build is inapplicable, it will be ignored during
                                       manifest processing.
2024-10-24 19:02:40       170          The streaming reader was created successfully for app package Microsoft.VCLibs.140.00.UWPDesktop_14.0.33321.0_x64__8wekyb3d8bbwe.
2024-10-24 19:02:40       10002        Creating Resiliency File
                                       C:\ProgramData\Microsoft\Windows\AppRepository\b11aecf4-f404-40fd-ad08-7c49d0ef4e96_S-1-5-21-2220047017-4043106817-3966502983-1002_65.rslc for Add
                                       Operation on Package PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj.
2024-10-24 19:02:40       607          Deployment Add operation on package PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj has been de-queued and is running for user SID
                                       S-1-5-21-2220047017-4043106817-3966502983-1002.
2024-10-24 19:02:40       854          Successfully added the following uri(s) to be processed:  file:///C:/Users/user/source/repos/PackageManagerRegisterTest/PackageManagerRegisterTest/bi
                                       n/x64/Debug/net8.0-windows10.0.22621.0/win-x64/AppPackages/PackageManagerRegisterTest_1.0.1.0_x64_Debug_Test/PackageManagerRegisterTest_1.0.1.0_x64_De
                                       bug.msix https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx.
2024-10-24 19:02:40       672          Package Microsoft.VCLibs.140.00.UWPDesktop_14.0.33321.0_x64__8wekyb3d8bbwe does not satisfy a dependency for package
                                       PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj. Reason: The package's version is lower than the required MinVersion.
2024-10-24 19:02:40       672          Package Microsoft.VCLibs.140.00.UWPDesktop_14.0.33519.0_x64__8wekyb3d8bbwe does not satisfy a dependency for package
                                       PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj. Reason: The package's version is lower than the required MinVersion.
2024-10-24 19:02:40       672          Package Microsoft.VCLibs.140.00.UWPDesktop_14.0.33519.0_x86__8wekyb3d8bbwe does not satisfy a dependency for package
                                       PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj. Reason: The package's version is lower than the required MinVersion.
2024-10-24 19:02:40       855          Finished resolving action lists. DeploymentRequest action lists: updateList: PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj is updating to
                                       PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj.
2024-10-24 19:02:43       638          Packages were not updated because affected apps are still running.  Running apps: {PackageManagerRegisterTest_ad8pwfkyh69vj!App}, Directly serviced
                                       packages: {PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj}, Indirectly serviced
                                       packages: {NULL}, Number of previous attempts: 0, Is user session locked: false, Force update deferred by package: false
2024-10-24 19:02:43       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x0, Set=0x20).
2024-10-24 19:02:43       638          Packages were not updated because affected apps are still running.  Running apps: {PackageManagerRegisterTest_ad8pwfkyh69vj!App}, Directly serviced
                                       packages: {PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj}, Indirectly serviced packages: {NULL}, Number of previous attempts: 0, Is user
                                       session locked: false, Force update deferred by package: false
2024-10-24 19:02:43       658          Marking package {PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj} for deferred registration because
                                       {PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj} is still running.
2024-10-24 19:02:43       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.0.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x0, Set=0x400).
2024-10-24 19:02:43       617          Successfully updated the status for package PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj and user
                                       S-1-5-21-2220047017-4043106817-3966502983-1002 (Clear=0x20, Set=0x0).
2024-10-24 19:02:43       400          Deployment Add operation with target volume C: on Package PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj from:
                                       (PackageManagerRegisterTest_1.0.1.0_x64_Debug.msix)  finished successfully.
2024-10-24 19:02:43       613          Performance summary of Deployment Add operation on Package PackageManagerRegisterTest_1.0.1.0_x64__ad8pwfkyh69vj:
                                       Overall time: 5141 ms
                                       Enqueue cost: 1657 ms
                                       Dequeue delay: 0 ms
                                       Bundle processing cost: 0 ms
                                       Indexing cost: 15 ms
                                       Resolve dependency cost: 16 ms
                                       Check approval cost: 0 ms
                                       Evaluation cost: 3016 ms
                                       Hardlinking evaluation cost: 203 ms
                                       Stage required cost: 62 ms
                                       Flushing and closing files cost: 0 ms
                                       Gap: 47 ms
                                       Machine register cost: 0 ms
                                       Stage user data cost: 0 ms
                                       Registration cost: 0 ms
                                       Repository commit transaction cost: 234 ms
                                       Gap: 47 ms
                                       Data flush cost: 16 ms
                                       Post DeStage repository commit transaction cost: 31 ms
                                       Remaining cost: 0 ms

Expected behavior

After executing an app update with DeferRegistrationWhenPackagesAreInUse = true AND with some DependencyPackageUris added, closing the app and reopening the app, the app opened is updated to the newest version.

Screenshots

No response

NuGet package version

Windows App SDK 1.6.1: 1.6.240923002

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

No response

@mominshaikhdevs
Copy link

mominshaikhdevs commented Oct 26, 2024

man, how buggy these "Deployment Manager APIs" are! these should be fixed asap.


Microsoft's @DrusTheAxe knows better.

@DrusTheAxe
Copy link
Member

A running package app uses AddPackageAsync with AddPackageOptions.DeferRegistrationWhenPackagesAreInUse=true to auto-update after quit and next run, but (re)Registers the old version instead of the new if any AddPackageOptions.DependencyPackageUris were specified? Now that's interesting.

PackageDeploymentManager passes its parameters down to PackageManager to do the heavy lifting. This appears to be an issue in Windows handling AddPackageOptions .DeferRegistrationWhenPackagesAreInUse=true & 1+ DependencyPackageUris. I have a hunch at the root cause but poking around the implementation hasn't turned up a smoking gun yet. Passing word to @cwruss for further investigation.

Thanks for bringing this to our attention!

@RDMacLachlan RDMacLachlan added area-Deployment Issues related to packaging, installation, runtime (e.g., SelfContained, Unpackaged) and removed needs-triage labels Oct 28, 2024
@DrusTheAxe
Copy link
Member

https://task.ms/55033078 for link to internal bug tracking this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Deployment Issues related to packaging, installation, runtime (e.g., SelfContained, Unpackaged)
Projects
None yet
Development

No branches or pull requests

4 participants