Skip to content

[dotnet] Compute _RelativeAppBundlePath correctly when the app bundle is on a different drive than the project. - #27407

Open
Kebechet wants to merge 1 commit into
dotnet:mainfrom
Kebechet:fix-relative-app-bundle-path-cross-drive
Open

Kebechet wants to merge 1 commit into
dotnet:mainfrom
Kebechet:fix-relative-app-bundle-path-cross-drive

Conversation

@Kebechet

Copy link
Copy Markdown

On Windows, MakeRelative can't compute a relative path between two drives, so when the output directory is on a different drive than the project (for example the project on D: and BaseOutputPath on C:), _AppBundlePath stays an absolute path. _ComputeVariables then appended it to the project directory, which produced a path with a drive letter in the middle:

_RelativeAppBundlePath=D:\src\MyApp\C:\out\MyApp\bin\Debug\net10.0-ios\iossimulator-arm64\MyApp.app\

Older MSBuild versions threw on this (MSB4184: The given path's format is not supported, reported in dotnet/maui#17438). Current MSBuild computes the corrupted value silently on every Windows build, and it flows into _AssemblyPublishDir, _DylibPublishDir, the RelativePath of ResolvedFileToPublish and the custom linker options.

This uses Path.Combine instead, which keeps an absolute path as-is and otherwise appends it to the project directory. Nothing changes on macOS, where _AppBundlePath is always relative.

To be transparent about the impact: I don't think this is user-visible in a supported scenario today. A build without a remote Mac doesn't consume the value, and remote builds reject an absolute OutputPath in _VerifyNoAbsoluteOutputPath before getting here. The same "project directory + possibly absolute path" pattern also exists in _AppExtensionBundlePath, _WatchAppBundlePath and the archive paths in Xamarin.iOS.Common.After.targets; this PR doesn't change those.

Tests

  • New WindowsTest.AppBundleOnDifferentDrive (category Windows, iOS and Mac Catalyst): runs _ComputeVariables with BaseOutputPath on another drive than the project and asserts _RelativeAppBundlePath is ..\MySimpleApp.app\. The other drive doesn't have to exist, nothing is written there.
  • The target-aware DotNet.GetProperty overload returned the trailing newline MSBuild writes to the result file, so I made it trim the value like the other GetProperty overload does.

I couldn't run the test against packs built from this branch (that needs a macOS build), so I ran it locally on Windows against the .NET 10 iOS / Mac Catalyst 26.5.10318 SDK packs with only this line patched: it fails without the fix (both platforms) and passes with it. Default output and same-drive absolute output give the same ..\MySimpleApp.app\ with and without the fix.

… is on a different drive than the project.

On Windows, MakeRelative can't compute a relative path between two drives, so
when the output directory is on a different drive than the project,
_AppBundlePath stays an absolute path. _ComputeVariables then appended it to
the project directory, which produced a path with a drive letter in the middle:

    _RelativeAppBundlePath=D:\src\MyApp\C:\out\MyApp\bin\Debug\net10.0-ios\iossimulator-arm64\MyApp.app\

Use Path.Combine instead, which keeps an absolute path as-is and otherwise
appends it to the project directory (so nothing changes on macOS, where
_AppBundlePath is always relative).

Also trim the result of the target-aware DotNet.GetProperty overload: MSBuild
writes a trailing newline after the value in the result file (the other
GetProperty overload already trims its result).

Ref: dotnet/maui#17438

This branch has not been deployed

No deployments
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.

1 participant