Skip to content

Conversation

@rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne commented Nov 28, 2025

This is a workaround dotnet/runtime#108269, where setting PublishTrimmed=true causes problems (and this is affecting and confusing more and more people).

This is a workaround dotnet/runtime#108269, where
setting PublishTrimmed=true causes problems.
@rolfbjarne rolfbjarne enabled auto-merge (squash) November 28, 2025 18:59
@rolfbjarne rolfbjarne requested a review from Copilot November 28, 2025 18:59
Copilot finished reviewing on behalf of rolfbjarne November 28, 2025 19:03
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 modifies the build system to disallow users from setting the PublishTrimmed property to any value (including true and false), as a workaround for dotnet/runtime#108269 where setting PublishTrimmed=true causes problems. Users must instead use platform-specific properties like LinkMode (macOS) or MtouchLink (iOS/tvOS/Mac Catalyst) to configure trimming behavior.

Key Changes

  • Updated error checking in _ComputePublishTrimmed target to reject any explicit PublishTrimmed value instead of just non-true values
  • Modified test cases to validate that both PublishTrimmed=false and PublishTrimmed=true now produce build errors
  • Updated error message to clarify that setting PublishTrimmed to any value is not supported

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
dotnet/targets/Xamarin.Shared.Sdk.targets Modified _ComputePublishTrimmed target to error when PublishTrimmed is set to any value, moved error check before property calculation
tests/dotnet/UnitTests/PublishTrimmedTest.cs Added test cases for both PublishTrimmed=true and PublishTrimmed=false, updated error message assertion to match new behavior

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines +12 to +15
[TestCase (ApplePlatform.iOS, "ios-arm64", "true")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64", "true")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64", "true")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64", "true")]
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

Test coverage for PublishTrimmed="true" is incomplete compared to PublishTrimmed="false". The test is missing cases for:

  • MacCatalyst with multi-RID ("maccatalyst-arm64;maccatalyst-x64")
  • MacOSX with single-RID ("osx-x64")

These should be added to ensure consistent coverage across all platform and RID combinations.

Copilot uses AI. Check for mistakes.
[TestCase (ApplePlatform.TVOS, "tvos-arm64", "true")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64", "true")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64", "true")]
public void DisableLinker (ApplePlatform platform, string runtimeIdentifiers, string value)
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The test method name DisableLinker is misleading. The test now validates that setting PublishTrimmed to ANY value (including "true") results in an error, not just disabling the linker. Consider renaming to something like PublishTrimmedNotSupported or SettingPublishTrimmedProducesError to better reflect the test's purpose.

Suggested change
public void DisableLinker (ApplePlatform platform, string runtimeIdentifiers, string value)
public void PublishTrimmedNotSupported (ApplePlatform platform, string runtimeIdentifiers, string value)

Copilot uses AI. Check for mistakes.
</PropertyGroup>
<Error Condition="'$(_MustTrim)' == 'true' And '$(PublishTrimmed)' != 'true'" Text="$(_PlatformName) projects must build with PublishTrimmed=true. Current value: $(PublishTrimmed). Set '$(_LinkModeProperty)=None' instead to disable trimming for all assemblies." />

<!-- The trimmer must be enabled, so if it was explicitly disabled, show an error. -->
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The first part of this comment is outdated. It says "The trimmer must be enabled, so if it was explicitly disabled, show an error" but the code now errors if PublishTrimmed is set to ANY value (not just when disabled). Consider updating the comment to: "Disallow setting 'PublishTrimmed' to any value. Users must use LinkMode/MtouchLink instead to configure trimming."

Suggested change
<!-- The trimmer must be enabled, so if it was explicitly disabled, show an error. -->
<!-- Disallow setting 'PublishTrimmed' to any value. Users must use LinkMode/MtouchLink instead to configure trimming. -->

Copilot uses AI. Check for mistakes.

<!-- The trimmer must be enabled, so if it was explicitly disabled, show an error. -->
<!-- Also disallow explicitly enabling the trimmer, because it causes problems (https://github.com/dotnet/runtime/issues/108269) -->
<Error Condition="'$(PublishTrimmed)' != ''" Text="$(_PlatformName) projects do not support setting 'PublishTrimmed' to any value (current value: $(PublishTrimmed)). Use the '$(_LinkModeProperty)' property to configure trimming behavior instead." />
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

This change will break the existing test case IsNotMacBuild in tests/dotnet/UnitTests/ProjectTest.cs at line 460, which sets PublishTrimmed=true along with IsMacEnabled=false and expects the build to succeed. With this change, the build will now fail with an error because PublishTrimmed is set to a non-empty value.

The test case at line 460 needs to be updated to either:

  1. Remove PublishTrimmed=true from the test's extraProperties, or
  2. Change the test to expect a build failure instead of success

Copilot uses AI. Check for mistakes.

<!-- The trimmer must be enabled, so if it was explicitly disabled, show an error. -->
<!-- Also disallow explicitly enabling the trimmer, because it causes problems (https://github.com/dotnet/runtime/issues/108269) -->
<Error Condition="'$(PublishTrimmed)' != ''" Text="$(_PlatformName) projects do not support setting 'PublishTrimmed' to any value (current value: $(PublishTrimmed)). Use the '$(_LinkModeProperty)' property to configure trimming behavior instead." />
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The documentation in docs/building-apps/build-properties.md at lines 1298-1300 needs to be updated to reflect this change. It currently states that an error is raised if PublishTrimmed is set to false, but with this change, an error will be raised if PublishTrimmed is set to ANY value (including true).

The documentation should be updated to say something like: "it's not valid to set PublishTrimmed to any value - to configure trimming behavior, use TrimMode, MtouchLink, or LinkMode instead (a build error will be raised if PublishTrimmed is set to any value)."

Suggested change
<Error Condition="'$(PublishTrimmed)' != ''" Text="$(_PlatformName) projects do not support setting 'PublishTrimmed' to any value (current value: $(PublishTrimmed)). Use the '$(_LinkModeProperty)' property to configure trimming behavior instead." />
<Error Condition="'$(PublishTrimmed)' != ''" Text="It's not valid to set 'PublishTrimmed' to any value for $(_PlatformName) projects (current value: $(PublishTrimmed)). To configure trimming behavior, use 'TrimMode', 'MtouchLink', or 'LinkMode' instead. A build error will be raised if 'PublishTrimmed' is set to any value." />

Copilot uses AI. Check for mistakes.
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #0dae187] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 0dae187456dc3813572f65509a1f8942b06bfbd2 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #0dae187] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 0dae187456dc3813572f65509a1f8942b06bfbd2 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 0dae187456dc3813572f65509a1f8942b06bfbd2 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #0dae187] Build failed (Build macOS tests) 🔥

Build failed for the job 'Build macOS tests' (with job status 'Failed')

Pipeline on Agent
Hash: 0dae187456dc3813572f65509a1f8942b06bfbd2 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #0dae187] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 14 tests failed, 101 tests passed.

Failures

❌ dotnettests tests (iOS)

1 tests failed, 0 tests passed.
  • DotNet tests: Failed (Execution failed with exit code 1)

Html Report (VSDrops) Download

❌ dotnettests tests (MacCatalyst)

1 tests failed, 0 tests passed.
  • DotNet tests: Failed (Execution failed with exit code 1)

Html Report (VSDrops) Download

❌ dotnettests tests (macOS)

1 tests failed, 0 tests passed.
  • DotNet tests: Failed (Execution failed with exit code 1)

Html Report (VSDrops) Download

❌ dotnettests tests (tvOS)

1 tests failed, 0 tests passed.
  • DotNet tests: Failed (Execution failed with exit code 1)

Html Report (VSDrops) Download

❌ interdependent-binding-projects tests

1 tests failed, 3 tests passed.
  • interdependent-binding-projects/tvOS - simulator/Debug: Crashed

Html Report (VSDrops) Download

❌ introspection tests

1 tests failed, 3 tests passed.
  • introspection/tvOS - simulator/Debug: Crashed

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

1 tests failed, 8 tests passed.
  • monotouch-test/iOS - simulator/Release (NativeAOT, x64): BuildFailure

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst)

3 tests failed, 8 tests passed.
  • monotouch-test/Mac Catalyst/Debug (static registrar): Failed (Test run crashed (exit code: 139).
    Test run crashed)
  • monotouch-test/Mac Catalyst/Release (NativeAOT): BuildFailure
  • monotouch-test/Mac Catalyst/Release (NativeAOT, x64): BuildFailure

Html Report (VSDrops) Download

❌ monotouch tests (macOS)

2 tests failed, 7 tests passed.
  • monotouch-test/macOS/Release (NativeAOT): BuildFailure
  • monotouch-test/macOS/Release (NativeAOT, x64): BuildFailure

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

1 tests failed, 8 tests passed.
  • monotouch-test/tvOS - simulator/Release (NativeAOT, x64): BuildFailure

Html Report (VSDrops) Download

❌ windows tests

1 tests failed, 0 tests passed.

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 0dae187456dc3813572f65509a1f8942b06bfbd2 [PR build]

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