Repository navigation
Add packaged-app identity/AUMID groundwork and Windows gating to PackagedApp extension #9914
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
main
from
dev/amauryleve/improve-packagedapp-extension
Jul 14, 2026
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
084511a
Improve PackagedApp extension with public-API-only groundwork
Evangelink 1c2ad90
Update .xlf files to be in sync with .resx
Evangelink 2ae1632
Address review: drop throwing Try* probe and add launcher tests
Evangelink 213236f
Add acceptance test for packaged-layout fail-fast
Evangelink bc457d6
Merge branch 'main' into dev/amauryleve/improve-packagedapp-extension
Evangelink 5016e78
Address PR review: resolve app by executable, honest packaged-app des…
Evangelink 785c906
Address second review pass: BOM, honest descriptions, correct trackin…
Evangelink d3abf8e
Correct public XML docs on packaged-app registration hooks
Evangelink 7f34eb3
Detect packaged layout when manifest is at an ancestor package root
Evangelink 86e9866
Drop UWP from the supported non-packaged path descriptions
Evangelink 13d6732
Merge branch 'main' into dev/amauryleve/improve-packagedapp-extension
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
src/Platform/Microsoft.Testing.Extensions.PackagedApp/AppxManifestInfo.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,157 @@ | ||
| // 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; | ||
|
|
||
| /// <summary> | ||
| /// The identity of a packaged Windows (UWP/WinUI) app, read from its <c>AppxManifest.xml</c>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// A packaged app is launched by <em>Application User Model ID</em> (AUMID), never by | ||
| /// <c>Process.Start</c>. The AUMID is <c>{PackageFamilyName}!{ApplicationId}</c>, and the package | ||
| /// family name is <c>{PackageName}_{publisherId}</c> where <c>publisherId</c> is a 13-character hash | ||
| /// of the manifest's <c>Publisher</c>. VSTest reads these values from VS-internal deployment | ||
| /// components; this type computes them from the manifest using only public, cross-platform managed | ||
| /// APIs so the extension does not depend on the Visual Studio install. | ||
| /// </para> | ||
| /// </remarks> | ||
| internal sealed class AppxManifestInfo | ||
|
Evangelink marked this conversation as resolved.
Resolved
|
||
| { | ||
| /// <summary> | ||
| /// The canonical file name of a packaged app's manifest inside its (loose or extracted) layout. | ||
| /// </summary> | ||
| internal const string AppxManifestFileName = "AppxManifest.xml"; | ||
|
|
||
| // The alphabet Windows uses to encode the publisher hash (Douglas Crockford's base32: the digits | ||
| // and lowercase letters with i, l, o and u removed). Must not be reordered. | ||
| private const string PublisherHashAlphabet = "0123456789abcdefghjkmnpqrstvwxyz"; | ||
|
|
||
| private AppxManifestInfo(string packageName, string publisher, string? applicationId) | ||
| { | ||
| PackageName = packageName; | ||
| Publisher = publisher; | ||
| ApplicationId = applicationId; | ||
| PackageFamilyName = $"{packageName}_{ComputePublisherId(publisher)}"; | ||
| AppUserModelId = applicationId is null ? null : $"{PackageFamilyName}!{applicationId}"; | ||
| } | ||
|
|
||
| /// <summary>Gets the package name (the manifest's <c>Identity/@Name</c>).</summary> | ||
| public string PackageName { get; } | ||
|
|
||
| /// <summary>Gets the publisher (the manifest's <c>Identity/@Publisher</c>).</summary> | ||
| public string Publisher { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the id of the first application declared in the manifest (<c>Applications/Application/@Id</c>), | ||
| /// or <see langword="null"/> when the manifest declares no application. | ||
| /// </summary> | ||
| public string? ApplicationId { get; } | ||
|
|
||
| /// <summary>Gets the package family name (<c>{PackageName}_{publisherId}</c>).</summary> | ||
| public string PackageFamilyName { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Application User Model ID (<c>{PackageFamilyName}!{ApplicationId}</c>) used to activate | ||
| /// the app, or <see langword="null"/> when the manifest declares no application. | ||
| /// </summary> | ||
| public string? AppUserModelId { get; } | ||
|
|
||
| /// <summary> | ||
| /// Reads the manifest at the root of <paramref name="layoutDirectory"/> if the directory is a | ||
| /// packaged-app layout. | ||
| /// </summary> | ||
| /// <param name="layoutDirectory">The directory to probe for an <c>AppxManifest.xml</c>.</param> | ||
| /// <param name="info">The parsed manifest info when the directory is a packaged-app layout.</param> | ||
| /// <returns> | ||
| /// <see langword="true"/> when an <c>AppxManifest.xml</c> was found and parsed; otherwise | ||
| /// <see langword="false"/>. | ||
| /// </returns> | ||
| public static bool TryReadFromLayout(string layoutDirectory, [NotNullWhen(true)] out AppxManifestInfo? info) | ||
| { | ||
| string manifestPath = Path.Combine(layoutDirectory, AppxManifestFileName); | ||
| if (!File.Exists(manifestPath)) | ||
| { | ||
| info = null; | ||
| return false; | ||
| } | ||
|
|
||
| info = ReadFromManifest(manifestPath); | ||
| return true; | ||
|
Evangelink marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| /// <summary>Reads and parses the manifest at <paramref name="manifestPath"/>.</summary> | ||
| /// <param name="manifestPath">The path to an <c>AppxManifest.xml</c>.</param> | ||
| /// <returns>The parsed manifest info.</returns> | ||
| public static AppxManifestInfo ReadFromManifest(string manifestPath) | ||
| { | ||
| using FileStream stream = File.OpenRead(manifestPath); | ||
| return ReadFromManifest(stream); | ||
| } | ||
|
|
||
| /// <summary>Reads and parses a manifest from <paramref name="manifestStream"/>.</summary> | ||
| /// <param name="manifestStream">A stream over an <c>AppxManifest.xml</c>.</param> | ||
| /// <returns>The parsed manifest info.</returns> | ||
| public static AppxManifestInfo ReadFromManifest(Stream manifestStream) | ||
| { | ||
| var document = XDocument.Load(manifestStream); | ||
| XElement? root = document.Root; | ||
|
|
||
| // Match by local name so we are resilient to the manifest schema version (the foundation | ||
| // namespace URI changes across Windows 10 SDK revisions). | ||
| XElement? identity = root?.Elements().FirstOrDefault(static e => e.Name.LocalName == "Identity"); | ||
| string? name = identity?.Attribute("Name")?.Value; | ||
| string? publisher = identity?.Attribute("Publisher")?.Value; | ||
|
|
||
| if (name is null || name.Length == 0 || publisher is null || publisher.Length == 0) | ||
| { | ||
| throw new InvalidOperationException(ExtensionResources.InvalidAppxManifestMissingIdentity); | ||
| } | ||
|
|
||
| string? applicationId = root?.Elements().FirstOrDefault(static e => e.Name.LocalName == "Applications")? | ||
| .Elements().FirstOrDefault(static e => e.Name.LocalName == "Application")? | ||
| .Attribute("Id")?.Value; | ||
|
Evangelink marked this conversation as resolved.
Resolved
Evangelink marked this conversation as resolved.
Resolved
Evangelink marked this conversation as resolved.
Resolved
|
||
|
|
||
| return new AppxManifestInfo(name, publisher, applicationId); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Computes the 13-character publisher id (the suffix of the package family name) for | ||
| /// <paramref name="publisher"/>, using the public Windows algorithm: base32-encode the first 8 | ||
| /// bytes of the SHA-256 hash of the UTF-16LE publisher string. | ||
| /// </summary> | ||
| /// <param name="publisher">The manifest's <c>Identity/@Publisher</c> value.</param> | ||
| /// <returns>The 13-character publisher id.</returns> | ||
| internal static string ComputePublisherId(string publisher) | ||
| { | ||
| byte[] hash = SHA256.HashData(Encoding.Unicode.GetBytes(publisher)); | ||
|
|
||
| // Take the first 8 bytes (64 bits) and encode them big-endian as 13 base32 characters. 64 bits | ||
| // is not a multiple of 5, so the final character carries the 4 leftover bits padded with a 0. | ||
| var builder = new StringBuilder(13); | ||
| int buffer = 0; | ||
| int bitsInBuffer = 0; | ||
| for (int i = 0; i < 8; i++) | ||
| { | ||
| buffer = (buffer << 8) | hash[i]; | ||
| bitsInBuffer += 8; | ||
| while (bitsInBuffer >= 5) | ||
| { | ||
| bitsInBuffer -= 5; | ||
| builder.Append(PublisherHashAlphabet[(buffer >> bitsInBuffer) & 0x1F]); | ||
| buffer &= (1 << bitsInBuffer) - 1; | ||
| } | ||
| } | ||
|
|
||
| if (bitsInBuffer > 0) | ||
| { | ||
| builder.Append(PublisherHashAlphabet[(buffer << (5 - bitsInBuffer)) & 0x1F]); | ||
| } | ||
|
|
||
| return builder.ToString(); | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
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,12 @@ | ||
| #nullable enable | ||
| Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo | ||
| Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.AppUserModelId.get -> string? | ||
| Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.ApplicationId.get -> string? | ||
| Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.PackageFamilyName.get -> string! | ||
| Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.PackageName.get -> string! | ||
| Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.Publisher.get -> string! | ||
| const Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.AppxManifestFileName = "AppxManifest.xml" -> string! | ||
| static Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.ComputePublisherId(string! publisher) -> string! | ||
| static Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.ReadFromManifest(System.IO.Stream! manifestStream) -> Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo! | ||
| static Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.ReadFromManifest(string! manifestPath) -> Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo! | ||
| static Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo.TryReadFromLayout(string! layoutDirectory, out Microsoft.Testing.Extensions.PackagedApp.AppxManifestInfo? info) -> bool |
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
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
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.