Skip to content

Fix iOS Custom Entitlements File Not Respected in Single Project Templates#30275

Merged
PureWeen merged 3 commits intoinflight/currentfrom
copilot/fix-30221
Aug 4, 2025
Merged

Fix iOS Custom Entitlements File Not Respected in Single Project Templates#30275
PureWeen merged 3 commits intoinflight/currentfrom
copilot/fix-30221

Conversation

Copy link
Contributor

Copilot AI commented Jun 27, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description

This PR fixes an issue where MAUI unconditionally overrides the CodesignEntitlements property when a default Entitlements.plist file exists, ignoring any custom entitlements file specified by the developer.

Problem

When developers set a custom entitlements file via the CodesignEntitlements property in their project file, MAUI's build targets would ignore this setting and always use Platforms\iOS\Entitlements.plist or Platforms\MacCatalyst\Entitlements.plist if those files exist. This causes build errors when the default entitlements don't match the provisioning profile requirements.

For example, a developer might configure:

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net9.0-ios|AnyCPU'">
  <CodesignEntitlements>Platforms\iOS\EntitlementsProduction.plist</CodesignEntitlements>
</PropertyGroup>

But MAUI would still use Platforms\iOS\Entitlements.plist, leading to errors like:

error MT7137: The app requests the entitlement 'aps-environment' with the value 'development', but the provisioning profile 'REDACTED' grants it for the value 'production'

Root Cause

In Microsoft.Maui.Controls.SingleProject.Before.targets, lines 47 and 53 unconditionally set the CodesignEntitlements property:

<CodesignEntitlements Condition=" Exists('$(iOSProjectFolder)Entitlements.plist') ">$(iOSProjectFolder)Entitlements.plist</CodesignEntitlements>

This overwrites any user-defined value, even when the developer has explicitly set a custom entitlements file.

Solution

Added a condition to check if CodesignEntitlements is already set before applying the default value:

<CodesignEntitlements Condition=" '$(CodesignEntitlements)' == '' and Exists('$(iOSProjectFolder)Entitlements.plist') ">$(iOSProjectFolder)Entitlements.plist</CodesignEntitlements>

This change:

  • ✅ Respects user-defined CodesignEntitlements property values
  • ✅ Still provides the default behavior when no custom entitlements are specified
  • ✅ Works for both iOS and MacCatalyst platforms
  • ✅ Maintains backward compatibility

Testing

Validated the fix with targeted MSBuild tests that verify:

  1. Custom CodesignEntitlements property is preserved when set by the user
  2. Default Entitlements.plist is still used when no custom property is set
  3. Both iOS and MacCatalyst platforms work correctly

Fixes #30221.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…d CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Copilot AI changed the title [WIP] iOS Custom Entitlements File Not Respected Fix iOS Custom Entitlements File Not Respected in Single Project Templates Jun 27, 2025
Copilot AI requested a review from jfversluis June 27, 2025 12:05
@jfversluis jfversluis added this to the .NET 9 SR9 milestone Jun 27, 2025
@jfversluis jfversluis moved this from Todo to Ready To Review in MAUI SDK Ongoing Jun 27, 2025
@jfversluis jfversluis marked this pull request as ready for review June 27, 2025 12:16
Copilot AI review requested due to automatic review settings June 27, 2025 12:16
@jfversluis jfversluis requested a review from a team as a code owner June 27, 2025 12:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an issue where MAUI was unconditionally overriding the CodesignEntitlements property and not respecting custom user settings for iOS and MacCatalyst.

  • Updated the condition for setting CodesignEntitlements in both iOS and MacCatalyst targets to only set the property when it is not already defined.
  • This change maintains backward compatibility and prevents build errors related to entitlement mismatches.

@jfversluis
Copy link
Member

jfversluis commented Jun 27, 2025

/azp run MAUI-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rmarinho
Copy link
Member

Can you added test ?

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue #30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 30, 2025

Can you added test ?

I've added comprehensive MSBuild tests for the CodesignEntitlements fix in commit 44c19ff. The tests verify both scenarios:

  1. SingleProject_CodesignEntitlementsRespected - confirms custom CodesignEntitlements property is preserved when set by the user
  2. SingleProject_DefaultEntitlementsUsedWhenNoCustomSet - ensures default Entitlements.plist is still used when no custom property is set

Both tests pass and validate the fix for issue #30221.

Copilot AI requested a review from rmarinho June 30, 2025 09:48
@jfversluis jfversluis modified the milestones: .NET 9 SR9, .NET 9 SR10 Jul 1, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis jfversluis moved this from Ready To Review to Approved in MAUI SDK Ongoing Jul 4, 2025
@PureWeen PureWeen changed the base branch from main to inflight/current August 4, 2025 22:05
@PureWeen PureWeen merged commit e1c5061 into inflight/current Aug 4, 2025
17 checks passed
@PureWeen PureWeen deleted the copilot/fix-30221 branch August 4, 2025 22:05
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Aug 4, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR10, .NET 9 SR11 Aug 4, 2025
github-actions bot pushed a commit that referenced this pull request Aug 7, 2025
…lates (#30275)

* Initial plan

* Fix iOS Custom Entitlements File override issue - respect user-defined CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>

* Add MSBuild tests for CodesignEntitlements fix

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue #30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
PureWeen pushed a commit that referenced this pull request Aug 8, 2025
…lates (#30275)

* Initial plan

* Fix iOS Custom Entitlements File override issue - respect user-defined CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>

* Add MSBuild tests for CodesignEntitlements fix

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue #30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Aug 11, 2025
…lates (#30275)

* Initial plan

* Fix iOS Custom Entitlements File override issue - respect user-defined CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>

* Add MSBuild tests for CodesignEntitlements fix

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue #30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Aug 15, 2025
…lates (#30275)

* Initial plan

* Fix iOS Custom Entitlements File override issue - respect user-defined CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>

* Add MSBuild tests for CodesignEntitlements fix

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue #30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Aug 15, 2025
…lates (#30275)

* Initial plan

* Fix iOS Custom Entitlements File override issue - respect user-defined CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>

* Add MSBuild tests for CodesignEntitlements fix

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue #30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Aug 19, 2025
…lates (#30275)

* Initial plan

* Fix iOS Custom Entitlements File override issue - respect user-defined CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>

* Add MSBuild tests for CodesignEntitlements fix

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue #30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
github-actions bot pushed a commit that referenced this pull request Aug 22, 2025
…lates (#30275)

* Initial plan

* Fix iOS Custom Entitlements File override issue - respect user-defined CodesignEntitlements

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>

* Add MSBuild tests for CodesignEntitlements fix

- Added SingleProject_CodesignEntitlementsRespected test to verify custom CodesignEntitlements property is preserved
- Added SingleProject_DefaultEntitlementsUsedWhenNoCustomSet test to verify default behavior still works
- Tests validate the fix for issue #30221 where custom entitlements were being overridden

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Sep 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

iOS Custom Entitlements File Not Respected

6 participants