Repository navigation
Fix PackagedApp registration when switching build layouts #11372
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
Merged
Amaury Levé (Evangelink)
merged 11 commits into
microsoft:main
from
Sergio0694:user/sergiopedri/packaged-layout-registration
Sep 21, 2026
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bc80c88
Fix packaged app registration when switching layouts
Sergio0694 c49ee24
Merge completed packaged app registration fix
Sergio0694 38c540a
Serialize packaged app registration and activation
Sergio0694 9868310
Complete packaged app registration repair on cancellation
Evangelink 5465422
Report packaged app restoration failures before cancellation
Evangelink 50a1a04
Merge branch 'main' into user/sergiopedri/packaged-layout-registration
Evangelink 4d710ac
Keep packaged app manifest and registration state consistent
Sergio0694 868c40f
Create missing crash dump registry key in CI
Sergio0694 d538026
Keep post-removal lookup failures outside deployment wrapping
Sergio0694 b2bfb29
Merge main into packaged app registration fix
Evangelink 122292d
Report packaged app removal failures accurately
Evangelink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/Platform/Microsoft.Testing.Extensions.PackagedApp/InternalAPI/InternalAPI.Unshipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,11 @@ | ||
| #nullable enable | ||
| Microsoft.Testing.Extensions.PackagedApp.PackageDeployer | ||
| Microsoft.Testing.Extensions.PackagedApp.PackageRegistrationLock | ||
| Microsoft.Testing.Extensions.PackagedApp.RegisteredPackageInfo | ||
| Microsoft.Testing.Extensions.PackagedApp.RegisteredPackageInfo.FullName.get -> string! | ||
| Microsoft.Testing.Extensions.PackagedApp.RegisteredPackageInfo.InstalledPath.get -> string! | ||
| Microsoft.Testing.Extensions.PackagedApp.RegisteredPackageInfo.IsDevelopmentMode.get -> bool | ||
| Microsoft.Testing.Extensions.PackagedApp.RegisteredPackageInfo.RegisteredPackageInfo(string! fullName, string! installedPath, bool isDevelopmentMode) -> void | ||
| static Microsoft.Testing.Extensions.PackagedApp.PackageDeployer.RegisterAsync(string! manifestPath, System.Func<System.Threading.CancellationToken, System.Threading.Tasks.Task!>! registerPackage, System.Func<System.Collections.Generic.IReadOnlyList<Microsoft.Testing.Extensions.PackagedApp.RegisteredPackageInfo!>!>! findRegisteredPackages, System.Func<string!, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>!>! removeDevelopmentPackage, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task! | ||
| static Microsoft.Testing.Extensions.PackagedApp.PackageRegistrationLock.AcquireAsync(string! packageFamilyName, string! lockDirectory, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.IO.FileStream!>! | ||
| static Microsoft.Testing.Extensions.PackagedApp.PackageRegistrationLock.AcquireAsync(string! packageFamilyName, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<System.IO.FileStream!>! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Platform/Microsoft.Testing.Extensions.PackagedApp/PackageRegistrationLock.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Security.Cryptography; | ||
|
|
||
| using Microsoft.Testing.Extensions.PackagedApp.Resources; | ||
|
|
||
| namespace Microsoft.Testing.Extensions.PackagedApp; | ||
|
|
||
| [SupportedOSPlatform("windows")] | ||
| internal static class PackageRegistrationLock | ||
| { | ||
| private const int SharingViolationHResult = unchecked((int)0x80070020); | ||
|
|
||
| public static Task<FileStream> AcquireAsync(string packageFamilyName, CancellationToken cancellationToken) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| string localApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | ||
| if (localApplicationData.Length == 0) | ||
| { | ||
| throw new InvalidOperationException(ExtensionResources.PackagedAppRegistrationLockDirectoryUnavailable); | ||
| } | ||
|
|
||
| // Keep the lock outside package-owned storage: registration may replace that storage and | ||
| // must establish its AppContainer ACL before the controller writes anything there. | ||
| string lockDirectory = Path.Combine(localApplicationData, "Microsoft.Testing.Platform", "PackagedApp", "RegistrationLocks"); | ||
| return AcquireAsync(packageFamilyName, lockDirectory, cancellationToken); | ||
| } | ||
|
|
||
| internal static async Task<FileStream> AcquireAsync(string packageFamilyName, string lockDirectory, CancellationToken cancellationToken) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| Directory.CreateDirectory(lockDirectory); | ||
| string lockName = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(packageFamilyName.ToUpperInvariant()))); | ||
| string lockPath = Path.Combine(lockDirectory, lockName + ".lock"); | ||
|
|
||
| while (true) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| try | ||
| { | ||
| // A file lease is not thread-affine and the OS releases it if the controller exits. | ||
| // Leave the file in place so every contender continues to lock the same file. | ||
| return new FileStream(lockPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); | ||
| } | ||
| catch (IOException ex) when (ex.HResult == SharingViolationHResult) | ||
| { | ||
| await Task.Delay(TimeSpan.FromMilliseconds(50), cancellationToken).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.