Skip to content

[cli] implement dotnet maui screenshot command#33551

Closed
jonathanpeppers wants to merge 8 commits intomainfrom
dev/peppers/cli
Closed

[cli] implement dotnet maui screenshot command#33551
jonathanpeppers wants to merge 8 commits intomainfrom
dev/peppers/cli

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented Jan 15, 2026

Spec: https://github.com/dotnet/maui/blob/5ecf21af9f043b74906abc8b5ae16368e9fa628b/docs/design/cli.md

Adds a new CLI tool for .NET MAUI that captures screenshots from
connected devices and emulators.

Key additions:

  • CLI infrastructure with Program.cs and CommonOptions.cs (shared
    options like --device and --framework)

  • ScreenshotCommand for capturing screenshots from Android, iOS,
    Windows, and macOS.

  • NativeMethods for Windows interop

  • Unit tests for root command, screenshot command, and platform
    detection

The CLI is packaged as a dotnet tool (Microsoft.Maui.Cli) and uses
dotnet/arcade's $(SuppressFinalPackageVersion) to remain in preview
when the rest of MAUI ships as stable.

Some examples:

# Basic screenshot from your desktop OS
dotnet maui screenshot

# Screenshot from default Android/adb connection
dotnet maui screenshot --framework net10.0-android

# Screenshot from a specific Android emulator
dotnet maui screenshot --framework net10.0-android --device emulator-5554

# Screenshot with a custom output filename
dotnet maui screenshot --output ./screenshots/home-screen.png

# Wait 3 seconds before capturing (for animations to complete)
dotnet maui screenshot -f net10.0-android -w 3 -o after-animation.png

# Verbose output for debugging
dotnet maui screenshot -f net10.0-android --verbose

# Get help
dotnet maui screenshot --help
dotnet maui --help

TODO:

  • Prompt for OS / device if unspecified. Similar to dotnet run.

  • --list-devices global option

  • iOS physical device screenshots

  • Use of .NET MAUI project in current directory.

  • Add more subcommands! dotnet maui log/logs, dotnet maui tree,
    etc.

Adds a new CLI tool for .NET MAUI that captures screenshots from
connected devices and emulators.

Key additions:

* CLI infrastructure with `Program.cs` and `CommonOptions.cs` (shared
  options like --device)

* `ScreenshotCommand` for capturing screenshots from Android, iOS,
  Windows, and macOS.

* `NativeMethods` for platform-specific interop operations

* Unit tests for root command, screenshot command, and platform
  detection

The CLI is packaged as a dotnet tool (`Microsoft.Maui.Cli`) and uses
dotnet/arcade's `$(SuppressFinalPackageVersion)` to remain in preview
when the rest of MAUI ships as stable.

Some examples:

    # Basic screenshot from your desktop OS
    dotnet maui screenshot

    # Screenshot from default Android/adb connection
    dotnet maui screenshot --framework net10.0-android

    # Screenshot from a specific Android emulator
    dotnet maui screenshot --framework net10.0-android --device emulator-5554

    # Screenshot with a custom output filename
    dotnet maui screenshot --output ./screenshots/home-screen.png

    # Wait 3 seconds before capturing (for animations to complete)
    dotnet maui screenshot -f net10.0-android -w 3 -o after-animation.png

    # Verbose output for debugging
    dotnet maui screenshot -f net10.0-android --verbose

    # Get help
    dotnet maui screenshot --help
    dotnet maui --help

TODO:

* Prompt for OS / device if unspecified. Similar to `dotnet run`.

* `--list-devices` global option

* iOS physical device screenshots

* Use of .NET MAUI project in current directory.

* Add more subcommands! `dotnet maui log/logs`, `dotnet maui tree`,
  etc.
@jonathanpeppers
Copy link
Copy Markdown
Member Author

New test project seems to be running on Mac & Windows:

image

@jonathanpeppers
Copy link
Copy Markdown
Member Author

/azp run

@jonathanpeppers jonathanpeppers marked this pull request as ready for review January 15, 2026 20:53
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Copy Markdown
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 adds a new dotnet maui screenshot CLI tool for capturing screenshots from Android, iOS, Windows, and macOS devices/emulators. The implementation includes complete CLI infrastructure with command parsing, platform-specific screenshot capture methods, and comprehensive unit tests.

Changes:

  • Added new CLI tool project (Microsoft.Maui.Cli) packaged as a dotnet tool with preview versioning
  • Implemented screenshot command with support for Android (adb), iOS Simulator (xcrun simctl), Mac Catalyst (screencapture), and Windows (Win32 APIs)
  • Added unit tests covering CLI commands, options, and platform detection logic

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Cli/src/Cli/Program.cs Entry point and root command setup
src/Cli/src/Cli/CommonOptions.cs Global CLI options (framework, device, project, verbose)
src/Cli/src/Cli/Commands/Screenshot/ScreenshotCommand.cs Screenshot command implementation with platform-specific handlers
src/Cli/src/Cli/NativeMethods.cs Windows P/Invoke declarations for screen capture
src/Cli/src/Cli/Cli.csproj CLI tool project configuration with preview versioning
src/Cli/tests/Cli.UnitTests/Cli.UnitTests.csproj Unit test project configuration
src/Cli/tests/Cli.UnitTests/CliTestHelper.cs Test helper for CLI command execution
src/Cli/tests/Cli.UnitTests/RootCommandTests.cs Tests for root command help and validation
src/Cli/tests/Cli.UnitTests/Commands/Screenshot/ScreenshotCommandTests.cs Tests for screenshot command options and execution
src/Cli/tests/Cli.UnitTests/Commands/Screenshot/GetTargetPlatformIdentifierTests.cs Tests for platform detection from TFM strings
eng/pipelines/arcade/stage-unit-tests.yml CI pipeline integration for unit tests
eng/Versions.props Added Xamarin.Android.Tools.AndroidSdk package version
eng/Version.Details.xml Added dependency details for Android SDK tools
NuGet.config Added package source for dotnet-android dependencies
Microsoft.Maui.sln Added CLI projects to main solution
Microsoft.Maui-vscode.sln Added CLI projects to VS Code solution
Microsoft.Maui-dev.sln Added CLI projects to dev solution

Comment thread src/Cli/src/Cli/Program.cs
Comment thread src/Cli/src/Cli/Commands/Screenshot/ScreenshotCommand.cs Outdated
Comment thread src/Cli/src/Cli/Commands/Screenshot/ScreenshotCommand.cs Outdated
@jonathanpeppers
Copy link
Copy Markdown
Member Author

/azp run maui-pr-uitests maui-pr-devicetests

@azure-pipelines
Copy link
Copy Markdown

No pipelines are associated with this pull request.

@jonathanpeppers
Copy link
Copy Markdown
Member Author

/azp run maui-pr-devicetests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jonathanpeppers
Copy link
Copy Markdown
Member Author

/azp run maui-pr-uitests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

jfversluis
jfversluis previously approved these changes Jan 16, 2026
Comment thread src/Cli/src/Cli/Commands/Screenshot/ScreenshotCommand.cs Outdated
Comment thread src/Cli/src/Cli/Commands/Screenshot/ScreenshotCommand.cs Outdated
Comment thread src/Cli/src/Cli/Commands/Screenshot/ScreenshotCommand.cs Outdated
Comment thread src/Cli/src/Cli/Commands/Screenshot/ScreenshotCommand.cs Outdated
Comment thread src/Cli/src/Cli/Commands/Screenshot/ScreenshotCommand.cs Outdated
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
Updated CreateProcessStartInfo to accept params string[] and populate ArgumentList, avoiding quoting issues with command arguments.
@jonathanpeppers
Copy link
Copy Markdown
Member Author

This is here now: https://github.com/dotnet/maui-labs

@github-actions github-actions Bot locked and limited conversation to collaborators May 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants