Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3ffcd36
Add scripts to download aspire-cli
radical Jul 3, 2025
06552a2
Update eng/scripts/get-aspire-cli.sh
radical Jul 3, 2025
c45b215
Merge remote-tracking branch 'origin/main' into get-aspire-cli-scripts
radical Jul 7, 2025
bc855ed
update the scripts
radical Jul 7, 2025
8c4edc4
Update eng/scripts/get-aspire-cli.sh
radical Jul 7, 2025
372f899
Update eng/scripts/get-aspire-cli.ps1
radical Jul 7, 2025
0820d14
add a README.md
radical Jul 7, 2025
8f4d0bc
update README.md
radical Jul 7, 2025
0621834
address review feedback from @ eerhardt
radical Jul 7, 2025
c8dccb8
Address review feedback from @ blowdart and use mime-type to detect w…
radical Jul 7, 2025
6664feb
fix ps1 for modern powershell
radical Jul 7, 2025
01ecfac
Cleanup the ps1 script
radical Jul 7, 2025
73b1379
clean up .sh script, and don't use that ldd is available
radical Jul 7, 2025
877c329
Merge remote-tracking branch 'origin/main' into get-aspire-cli-scripts
radical Jul 7, 2025
6561c32
Update eng/scripts/get-aspire-cli.ps1
radical Jul 8, 2025
41544b0
Use different names for persistent and session scoped networks (#10278)
danegsta Jul 7, 2025
affb837
Address review feedback from @ eerhardt and bump archive download tim…
radical Jul 8, 2025
95dfd0c
Address review feedback from @ eerhardt and change Channel parameter …
radical Jul 8, 2025
2fb6065
Merge remote-tracking branch 'origin/main' into get-aspire-cli-scripts
radical Jul 8, 2025
ae772b0
Address review feedback from @ eerhardt - update README.md
radical Jul 9, 2025
48b262f
Address review feedback - Rename BuildQuality to Quality
radical Jul 9, 2025
f788557
Merge remote-tracking branch 'origin/main' into get-aspire-cli-scripts
radical Jul 11, 2025
3986ae1
Merge remote-tracking branch 'origin/main' into get-aspire-cli-scripts
radical Jul 13, 2025
7e6506f
Improve Aspire CLI download script with auto-installation and PATH ma…
radical Jul 14, 2025
c09d588
update ps1
radical Jul 14, 2025
67908b4
Merge remote-tracking branch 'origin/main' into get-aspire-cli-scripts
radical Jul 14, 2025
e85ae0b
update README.md
radical Jul 14, 2025
2a43c92
Update eng/scripts/get-aspire-cli.sh
radical Jul 14, 2025
3baae6e
Add the install path to the PATH env var also
radical Jul 14, 2025
ef81d43
refactor to extract function to get install path
radical Jul 14, 2025
5b01fe0
Extract method to download and install the archive
radical Jul 14, 2025
323b9bc
some cleanup and refactoring
radical Jul 15, 2025
205d15b
cleanup
radical Jul 15, 2025
cd1d032
Update eng/scripts/get-aspire-cli.sh
radical Jul 15, 2025
4d6e44e
fix script
radical Jul 15, 2025
a0dadea
Merge remote-tracking branch 'origin/main' into get-aspire-cli-scripts
radical Jul 15, 2025
d12589b
Address review feedback from @ davidfowl
radical Jul 15, 2025
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
127 changes: 127 additions & 0 deletions eng/scripts/get-aspire-cli.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env pwsh

[CmdletBinding()]
param()

$ErrorActionPreference = 'Stop'

# Define supported combinations (script-level constant)
$script:SupportedCombinations = @(
"win-x86",
"win-x64",
"win-arm64",
"linux-x64",
"linux-arm64",
"linux-musl-x64",
"osx-x64",
"osx-arm64"
)

# Function to detect OS
function Get-OperatingSystem {
if ($IsWindows -or ($PSVersionTable.PSVersion.Major -le 5)) {
return "win"
}
elseif ($IsLinux) {
# Check if it's musl-based (Alpine, etc.)
try {
$lddOutput = & ldd --version 2>&1 | Out-String
if ($lddOutput -match "musl") {
return "linux-musl"
}
else {
return "linux"
}
}
catch {
return "linux"
}
}
elseif ($IsMacOS) {
return "osx"
}
else {
return "unsupported"
}
}

# Function to detect architecture
function Get-Architecture {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture

switch ($arch) {
"X64" { return "x64" }
"Arm64" { return "arm64" }
"X86" { return "x86" }
default { return "unsupported" }
}
}

# Function to validate OS/arch combination
function Test-SupportedCombination {
param(
[string]$OS,
[string]$Architecture
)

$combination = "$OS-$Architecture"

return $combination -in $script:SupportedCombinations
}

# Main function
function Main {
try {
# Detect OS and architecture
$os = Get-OperatingSystem
$arch = Get-Architecture

# Check for unsupported OS or architecture
if ($os -eq "unsupported") {
Write-Error "Error: Unsupported operating system: $([System.Environment]::OSVersion.Platform)"
exit 1
}

if ($arch -eq "unsupported") {
Write-Error "Error: Unsupported architecture: $([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)"
exit 1
}

# Validate the combination
if (-not (Test-SupportedCombination -OS $os -Architecture $arch)) {
Write-Error "Error: Unsupported OS/architecture combination: $os-$arch"
Write-Error "Supported combinations: $($script:SupportedCombinations -join ', ')"
exit 1
}

# Determine file extension based on OS
$extension = if ($os -eq "win") { "zip" } else { "tar.gz" }

# Construct the URL
$combination = "$os-$arch"
$url = "https://aka.ms/dotnet/9.0/daily/aspire-cli-$combination.$extension"

# Output the URL
Write-Host "Downloading from: $url"

# Download the file
$filename = "aspire-cli-$combination.$extension"
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.

Write-Host "Download completed successfully: $filename" -ForegroundColor Green
}
catch {
Write-Error "Error: Failed to download $url - $($_.Exception.Message)"
exit 1
}
}
catch {
Write-Error "An error occurred: $($_.Exception.Message)"
exit 1
}
}

# Run main function
Main
145 changes: 145 additions & 0 deletions eng/scripts/get-aspire-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/usr/bin/env bash

# get-aspire-cli.sh - Download the Aspire CLI for the current platform
# Usage: ./get-aspire-cli.sh

set -euo pipefail

# Define supported combinations (global constant)
readonly SUPPORTED_COMBINATIONS=(
"win-x86"
"win-x64"
"win-arm64"
"linux-x64"
"linux-arm64"
"linux-musl-x64"
"osx-x64"
"osx-arm64"
)

# Function to detect OS
get_os() {
local uname_s
uname_s=$(uname -s)

case "$uname_s" in
Darwin*)
printf "osx"
;;
Linux*)
# Check if it's musl-based (Alpine, etc.)
if ldd --version 2>&1 | grep -q musl; then
printf "linux-musl"
else
printf "linux"
fi
;;
CYGWIN*|MINGW*|MSYS*)
printf "win"
;;
*)
printf "unsupported"
return 1
;;
esac
}

# Function to detect architecture
get_arch() {
local uname_m
uname_m=$(uname -m)

case "$uname_m" in
x86_64|amd64)
printf "x64"
;;
aarch64|arm64)
printf "arm64"
;;
i386|i686)
printf "x86"
;;
*)
printf "unsupported"
return 1
;;
esac
}

# Function to validate OS/arch combination
validate_combination() {
local os="$1"
local arch="$2"
local combination="${os}-${arch}"

local supported_combo
for supported_combo in "${SUPPORTED_COMBINATIONS[@]}"; do
if [[ "$combination" == "$supported_combo" ]]; then
return 0
fi
done

return 1
}

# Download the Aspire CLI for the current platform
download_aspire_cli() {
local url="$1"
local filename="$2"

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.

printf "Download completed successfully: %s\n" "$filename"
return 0
else
printf "Error: Failed to download %s\n" "$url" >&2
return 1
fi
}

# Main script
main() {
local os arch combination url filename

# Detect OS and architecture
if ! os=$(get_os); then
printf "Error: Unsupported operating system: %s\n" "$(uname -s)" >&2
return 1
fi

if ! arch=$(get_arch); then
printf "Error: Unsupported architecture: %s\n" "$(uname -m)" >&2
return 1
fi

# Validate the combination
if ! validate_combination "$os" "$arch"; then
combination="${os}-${arch}"
printf "Error: Unsupported OS/architecture combination: %s\n" "$combination" >&2
printf "Supported combinations: %s\n" "${SUPPORTED_COMBINATIONS[*]}" >&2
return 1
fi

# Construct the URL and filename
combination="${os}-${arch}"

# Determine file extension based on OS
if [[ "$os" == "win" ]]; then
extension="zip"
else
extension="tar.gz"
fi
Comment on lines +553 to +557
Copy link
Member

Choose a reason for hiding this comment

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

I think the osx files are extension .zip.

<ArchiveFormat Condition="$(CliRuntime.StartsWith('linux-'))">tar.gz</ArchiveFormat>
<ArchiveFormat Condition="!$(CliRuntime.StartsWith('linux-'))">zip</ArchiveFormat>

Copy link
Member Author

Choose a reason for hiding this comment

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

That will change with #10275


url="https://aka.ms/dotnet/9.0/daily/aspire-cli-${combination}.${extension}"
filename="aspire-cli-${combination}.${extension}"

# Download the file
download_aspire_cli "$url" "$filename"
}

# Run main function if script is executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi