Skip to content

Explain how a provisioning profile is selected - #202

Merged
rolfbjarne merged 2 commits into
mainfrom
dev/rolf/provisioning-profile-logging
Nov 18, 2026
Merged

rolfbjarne merged 2 commits into
mainfrom
dev/rolf/provisioning-profile-logging

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

GetMobileProvision used to load the first file named
'.mobileprovision' it found, without looking at any other
profiles. A hand-copied profile in the old
~/Library/MobileDevice/Provisioning Profiles directory would then hide
a newer profile with the same name in Xcode's current
~/Library/Developer/Xcode/UserData/Provisioning Profiles directory, even
if the hand-copied one had expired. Nothing in the build log showed
that this happened.

Now all profiles in both directories are checked:

  • A profile matches if its name, UUID or file name matches.
  • Expired profiles are skipped, unless every matching profile has
    expired (then the newest one is used, like before).
  • The newest matching profile is used.
  • Every profile is logged, with its full path and the reason it was
    or wasn't used.

Also add the full path to the messages from GetMobileProvisions, and
rebuild the profile index when a profile file is overwritten (this
doesn't change the modification date of the directory).

🤖 Pull request created by Copilot

GetMobileProvision used to load the first file named
'<profile name>.mobileprovision' it found, without looking at any other
profiles. A hand-copied profile in the old
~/Library/MobileDevice/Provisioning Profiles directory would then hide
a newer profile with the same name in Xcode's current
~/Library/Developer/Xcode/UserData/Provisioning Profiles directory, even
if the hand-copied one had expired. Nothing in the build log showed
that this happened.

Now all profiles in both directories are checked:

* A profile matches if its name, UUID or file name matches.
* Expired profiles are skipped, unless every matching profile has
  expired (then the newest one is used, like before).
* The newest matching profile is used.
* Every profile is logged, with its full path and the reason it was
  or wasn't used.

Also add the full path to the messages from GetMobileProvisions, and
rebuild the profile index when a profile file is overwritten (this
doesn't change the modification date of the directory).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f60b31f7-1c81-4100-858f-6b1c5b96f610
Copilot AI balanced review requested due to automatic review settings November 18, 2026 10:17
@rolfbjarne

Copy link
Copy Markdown
Member Author

@dalexsoto review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Profile lookup can miss repaired files excluded from the index and differently cased filenames on case-insensitive filesystems.

2 open issues
What changed in this PR

This PR makes provisioning-profile selection in Xamarin.MacDev easier to diagnose and prevents an older, expired profile from hiding a newer valid match.

Changes:

  • Scan both profile directories for name, UUID, or filename matches, preferring the newest unexpired profile.
  • Include full profile paths and selection reasons in diagnostic logs.
  • Detect overwrites of indexed profiles and add selection and expired-fallback tests.
File Description
Xamarin.MacDev/​MobileProvisionIndex.cs Updates profile selection, cache invalidation, and diagnostic logging.
tests/​TestMobileProvisionIndex.cs Adds profile fixtures and tests for newest-valid selection and expired fallback.

Review effort: Balanced

Comment thread Xamarin.MacDev/MobileProvisionIndex.cs Resolved
Comment thread Xamarin.MacDev/MobileProvisionIndex.cs Resolved
Track profile files that could not be parsed in the provisioning-profile
index. If one is repaired in place, its changed modification time now
invalidates the index so the profile can be loaded on the next lookup.
Also compare profile filenames without regard to case, matching the
previous file-system lookup behavior on case-insensitive volumes.

Add regression tests for both cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f60b31f7-1c81-4100-858f-6b1c5b96f610

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 30d09f1f against main at 8ed5915d (that's also the merge base). This was a static, read-only review of both changed files, the other code that calls them, and the dotnet/macios DetectSigningIdentity caller.

The new selection logic does what the description says. Profiles match by name, UUID or file name. Expired profiles are skipped unless every match has expired, and then the newest one by CreationDate is used, the same as the old index lookup. Both earlier review comments are fixed and have regression tests:

  • A profile that failed to parse is now tracked in UnindexedProfileFiles and gets re-read after it's repaired in place.
  • File-name and extension matching are now case-insensitive.

Changing IndexVersion to 2 makes both old and new code rebuild an index written by the other version. A corrupted or truncated index falls through to OpenIndex's catch, which rebuilds it. The changes in the GetMobileProvisions overloads only affect log text, and all the new messages are logged at normal importance. The public GetMobileProvision signature is unchanged.

Not blocking: the GetMobileProvisions overloads still compare the file extension case-sensitively, so a profile with an upper-case extension is skipped there. It was skipped before this PR too, so you could handle it in a follow-up if you want everything to be consistent.

@rolfbjarne
rolfbjarne merged commit 4490e9b into main Nov 18, 2026
7 checks passed
rolfbjarne added a commit to dotnet/macios that referenced this pull request Nov 24, 2026
Update Xamarin.MacDev to include the fix from dotnet/macios-devtools#203. The parser now reads complete `<true></true>` and `<false></false>` elements, keeping all following entries when converting plist resources to binary.

The dependency update also includes:

* dotnet/macios-devtools#198: add plist-loading overloads that return errors.
* dotnet/macios-devtools#200: use LF line endings in XML plist headers.
* dotnet/macios-devtools#201: update CI.
* dotnet/macios-devtools#202: check all profiles in both provisioning-profile folders when selecting one.

Add a regression test that converts plists with both boolean values to binary and checks that no entries are lost.

Fixes #27414

🤖 Pull request created by Copilot

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rolf Bjarne Kvinge <rokvin@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants