Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ Only applicable to macOS and Mac Catalyst projects.

See [BuildIpa](#buildipa) for iOS and tvOS projects.

## Device

Specifies which mobile device or emulator to target when using `dotnet run
--device <Device>` or MSBuild targets that interact with devices (such as
`Run`, `Install`, or `Uninstall`).

The value can be anything the command-line tools `simctl` or `devicectl`
accept for the device name; this is typically either the UDID or the name of
the device. For example, for the device `My iOS Device` with UDID `0000-aaaabbbb`, use
either `-p:Device="My iOS Device"` or `-p:Device=0000-aaaabbbb`.
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

Inconsistent code formatting: The second command example should use backticks for consistency with the first example. Change -p:Device=0000-aaaabbbb to `-p:Device=0000-aaaabbbb`.

Copilot uses AI. Check for mistakes.

For more information about device selection, see the
[.NET SDK device selection specification](https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md).

## DeviceSpecificBuild

If the build should be specific to the selected device.
Expand Down
31 changes: 29 additions & 2 deletions docs/building-apps/build-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,38 @@ Builds the source code within a project and all dependencies.

Removes all files generated by the build process.

## ComputeAvailableDevices

Queries and returns a list of available iOS or tvOS devices and simulators that can be used with `dotnet run`.

This target is called automatically by the .NET SDK's `dotnet run` command to
support device selection via the `--device` option. It returns a `@(Devices)``
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

There's a double backtick after @(Devices). It should be @(Devices) with no trailing backticks.

Suggested change
support device selection via the `--device` option. It returns a `@(Devices)``
support device selection via the `--device` option. It returns a `@(Devices)`

Copilot uses AI. Check for mistakes.
item group where each device has the following metadata:

- **Description**: The name of the device (e.g., "iPhone 16 - iOS 26.0" for simulators, "My iPhone 16" for physical devices)
- **Type**: Either "Device" or "Simulator"
- **OSVersion**: The OS version if the device
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

Grammar error: should be "The OS version of the device" instead of "The OS version if the device".

Suggested change
- **OSVersion**: The OS version if the device
- **OSVersion**: The OS version of the device

Copilot uses AI. Check for mistakes.
- **UDID**: The UDID of the device

For example, to list all available devices:

```shell
$ dotnet build -t:ComputeAvailableDevices
```

This target is part of the [.NET SDK device selection specification](https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md) and enables commands like:

```shell
$ dotnet run --device UDID
```

Added in .NET 11.

## Run

Builds the source code within a project and all dependencies, and then deploys and runs it
on a default simulator/device. A specific deployment target can be set by using the `$(_DeviceName)` property.
on a default simulator/device. A specific deployment target can be set by using the `$(Device)` property.

```dotnetcli
dotnet build -t:Run project.csproj -p:_DeviceName=$(MY_DEVICE_UDID)
dotnet build -t:Run project.csproj -p:Device=$(MY_DEVICE_UDID)
```
32 changes: 30 additions & 2 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2407,7 +2407,8 @@
<RelativeMlaunchPath Condition="'$(RelativeMlaunchPath)' == ''">$(XamarinRelativeSdkRootDirectory)tools\bin\mlaunch</RelativeMlaunchPath>
<_RelativeMlaunchPath Condition="'$(_RelativeMlaunchPath)' == ''">$(RelativeMlaunchPath)</_RelativeMlaunchPath>

<DeviceName Condition="'$(DeviceName)' == ''">$(_DeviceName)</DeviceName>
<!-- Try to keep _DeviceName working for a while yet -->
<Device Condition="'$(Device)' == ''">$(_DeviceName)</Device>
Comment on lines -2410 to +2411
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to keep $(DeviceName) around, it's public? Maybe it's not really used/documented.

</PropertyGroup>

<Target
Expand Down Expand Up @@ -2445,7 +2446,7 @@
<GetMlaunchArguments
SessionId="$(BuildSessionId)"
AppManifestPath="$(_AppBundleManifestPath)"
DeviceName="$(DeviceName)"
DeviceName="$(Device)"
InstallApp="$(_AppBundlePath)"
MlaunchPath="$(MlaunchPath)"
SdkDevPath="$(_SdkDevPath)"
Expand Down Expand Up @@ -2558,6 +2559,33 @@
</PropertyGroup>
</Target>

<!--
***********************************************************************************************
ComputeAvailableDevices
Target that queries available devices and simulators.
This target is called by 'dotnet run' to support device selection.
Returns @(Devices) items with metadata: ???????
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The comment states "Returns @(Devices) items with metadata: ???????" which appears to be a placeholder that was not filled in. The metadata should be documented here (Description, Type, OSVersion, UDID) similar to what's in the build-targets.md documentation.

Suggested change
Returns @(Devices) items with metadata: ???????
Returns @(Devices) items with metadata: Description, Type, OSVersion, UDID

Copilot uses AI. Check for mistakes.
See: https://github.com/dotnet/sdk/blob/2b9fc02a265c735f2132e4e3626e94962e48bdf5/documentation/specs/dotnet-run-for-maui.md
***********************************************************************************************
-->
<Target Name="ComputeAvailableDevices"
DependsOnTargets="_DetectSdkLocations;_GenerateBundleName;"
Returns="@(Devices)">
<GetAvailableDevices
Condition="'$(IsMacEnabled)' == 'true'"
SessionId="$(BuildSessionId)"
Comment on lines +2577 to +2578
Copy link
Member

Choose a reason for hiding this comment

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

That is a question... Will this work on Windows? Ideally, it could, but that could be future PR.

AppBundleManifestPath="$(_AppBundleManifestPath)"
RuntimeIdentifier="$(RuntimeIdentifier)"
SdkDevPath="$(_SdkDevPath)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
>
<Output TaskParameter="Devices" ItemName="Devices" />
<Output TaskParameter="DiscardedDevices" ItemName="DiscardedDevices" />
</GetAvailableDevices>
</Target>

<!--
Add a 'global using nfloat = System.Runtime.InteropServices.NFloat' to ease migration from Xamarin.
We're not using a the Usings item group, because this code shows a warning in .NET 7:
Expand Down
Loading
Loading