Apple platform
iOS
Framework version
net9.0-*
Affected platform version
9.0.200
Description
Title
MSBuild fails to launch iOS simulator when mlaunch path contains spaces (error 127)
Description
When using dotnet build -t:Run -f net9.0-ios to launch a .NET MAUI app in the iOS simulator, the command fails with error code 127 if the path to mlaunch contains spaces. This is due to MSBuild not properly escaping spaces in paths when creating temporary shell scripts.
The issue only occurs when using the combined build and run command. Running mlaunch directly with properly quoted paths works correctly.
Environment
- macOS 24.3.0
- .NET SDK 9.0.200
- Xcode (latest version)
- .NET MAUI workload installed via
dotnet workload install maui
Investigation Results
Looking at the diagnostic output with -v:diag, we found that:
- MSBuild creates a temporary shell script in
/var/folders/m_/v89b4sb95fz2lbt83sy2yjyh0000gn/T/MSBuildTempnat/
- The shell script fails because it doesn't properly handle spaces in the path:
/var/folders/m_/v89b4sb95fz2lbt83sy2yjyh0000gn/T/MSBuildTempnat/tmpf996f3bc7039479b8f6d69a939bafc4f.exec.cmd: line 2: /Users/nat/Library/Application: No such file or directory
- This causes the shell script to exit with code 127 (command not found)
- The named pipe between MSBuild processes breaks:
System.IO.IOException: Pipe is broken.
at System.IO.Pipes.NamedPipeServerStream.CheckConnectOperationsServer()
at System.IO.Pipes.NamedPipeServerStream.WaitForConnectionAsync(CancellationToken cancellationToken)
at Microsoft.Build.BackEnd.NodeEndpointOutOfProcBase.PacketPumpProc()
- MSBuild reports the error 127 from the shell script
Further investigation reveals that the issue originates in /Users/nat/Library/Application Support/dnvm/dn/packs/Microsoft.iOS.Sdk.net9.0_18.2/18.2.9180/targets/Xamarin.Shared.Sdk.targets. The MlaunchPath property is defined but not properly escaped for shell execution:
<PropertyGroup>
<MlaunchPath Condition="'$(MlaunchPath)' == '' And '$(_MlaunchPath)' != ''">$(_MlaunchPath)</MlaunchPath>
<MlaunchPath Condition="'$(MlaunchPath)' == ''">$(_XamarinSdkRootDirectory)tools\bin\mlaunch</MlaunchPath>
<!-- The path needs proper escaping here -->
</PropertyGroup>
This property is later used in the _InstallMobile target to execute mlaunch:
<Exec SessionId="$(BuildSessionId)" Command="$(MlaunchPath) $(MlaunchInstallArguments)" />
When MSBuild generates the shell script from this Exec task, it doesn't properly escape the spaces in the path, leading to the shell interpreting "/Users/nat/Library/Application" as the command to execute.
Expected Behavior
The command dotnet build -t:Run -f net9.0-ios should properly handle paths with spaces when creating temporary shell scripts, allowing the app to launch in the iOS simulator.
Actual Behavior
The command fails with error 127 due to improper handling of spaces in paths.
Additional Notes
- The issue is not with mlaunch itself, as it works when run directly with proper quoting
- The issue appears to be in how MSBuild creates and executes temporary shell scripts
- This affects any .NET MAUI iOS development where the SDK is installed in a path containing spaces
Suggested Fix
MSBuild should properly escape paths containing spaces when creating temporary shell scripts for executing commands. This could be done by:
- Properly quoting paths in the generated shell script
- Using appropriate shell escaping for spaces and special characters
- Or avoiding the creation of a shell script altogether and executing mlaunch directly
Impact
This issue affects the developer experience for .NET MAUI iOS development, requiring developers to use a workaround instead of the documented approach. This is particularly impactful because:
- The default installation paths on macOS often contain spaces
- The error message (127) is not descriptive of the actual issue
- The documented approach in the official documentation doesn't work in this common scenario
Steps to Reproduce
Steps to Reproduce
- Create a new MAUI project:
dotnet new maui -n "MauiBlazorWeb"
cd MauiBlazorWeb
- Try to build and run:
dotnet build -t:Run -f net9.0-ios
- Observe error:
error MSB3073: The command "/Users/nat/Library/Application Support/dnvm/dn/packs/Microsoft.iOS.Sdk.net9.0_18.2/18.2.9180/tools/bin/mlaunch --launchsim bin/Debug/net9.0-ios/iossimulator-arm64/MauiBlazorWeb.app/ --device ":v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-18-2,devicetype=com.apple.CoreSimulator.SimDeviceType.iPad-mini-A17-Pro" --stdout /dev/ttys056 --stderr /dev/ttys056 --wait-for-exit:true" exited with code 127.
- However, building separately works:
dotnet build -f net9.0-ios
- And running mlaunch directly with proper quoting works:
'/Users/nat/Library/Application Support/dnvm/dn/packs/Microsoft.iOS.Sdk.net9.0_18.2/18.2.9180/tools/bin/mlaunch' --launchsim bin/Debug/net9.0-ios/iossimulator-arm64/MauiBlazorWeb.app/ --device ':v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-18-2,devicetype=com.apple.CoreSimulator.SimDeviceType.iPad-mini-A17-Pro' --stdout /dev/ttys056 --stderr /dev/ttys056 --wait-for-exit:true
Did you find any workaround?
Workaround
Split the process into two steps:
dotnet build -f net9.0-ios
- Run mlaunch directly with proper path quoting
Relevant logs
No response
Apple platform
iOS
Framework version
net9.0-*
Affected platform version
9.0.200
Description
Title
MSBuild fails to launch iOS simulator when mlaunch path contains spaces (error 127)
Description
When using
dotnet build -t:Run -f net9.0-iosto launch a .NET MAUI app in the iOS simulator, the command fails with error code 127 if the path tomlaunchcontains spaces. This is due to MSBuild not properly escaping spaces in paths when creating temporary shell scripts.The issue only occurs when using the combined build and run command. Running
mlaunchdirectly with properly quoted paths works correctly.Environment
dotnet workload install mauiInvestigation Results
Looking at the diagnostic output with
-v:diag, we found that:/var/folders/m_/v89b4sb95fz2lbt83sy2yjyh0000gn/T/MSBuildTempnat/Further investigation reveals that the issue originates in
/Users/nat/Library/Application Support/dnvm/dn/packs/Microsoft.iOS.Sdk.net9.0_18.2/18.2.9180/targets/Xamarin.Shared.Sdk.targets. TheMlaunchPathproperty is defined but not properly escaped for shell execution:This property is later used in the
_InstallMobiletarget to execute mlaunch:When MSBuild generates the shell script from this Exec task, it doesn't properly escape the spaces in the path, leading to the shell interpreting "/Users/nat/Library/Application" as the command to execute.
Expected Behavior
The command
dotnet build -t:Run -f net9.0-iosshould properly handle paths with spaces when creating temporary shell scripts, allowing the app to launch in the iOS simulator.Actual Behavior
The command fails with error 127 due to improper handling of spaces in paths.
Additional Notes
Suggested Fix
MSBuild should properly escape paths containing spaces when creating temporary shell scripts for executing commands. This could be done by:
Impact
This issue affects the developer experience for .NET MAUI iOS development, requiring developers to use a workaround instead of the documented approach. This is particularly impactful because:
Steps to Reproduce
Steps to Reproduce
Did you find any workaround?
Workaround
Split the process into two steps:
dotnet build -f net9.0-iosRelevant logs
No response