Skip to content

Commit e04e9ce

Browse files
authored
Fix dotnet latest resolution (#1598)
* Fix dotnet latest resolution * Restore latest version check in test * Avoid silently ignoring CDN errors * Clarify dotnet latest target selection * test(dotnet): source staged feature helper script
1 parent 0c2cd3f commit e04e9ce

File tree

9 files changed

+50
-76
lines changed

9 files changed

+50
-76
lines changed

src/dotnet/NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Installing .NET workloads. Multiple workloads can be specified as comma-separate
6767
``` json
6868
"features": {
6969
"ghcr.io/devcontainers/features/dotnet:2": {
70-
"workloads": "aspire, wasm-tools"
70+
"workloads": "wasm-tools"
7171
}
7272
}
7373
```

src/dotnet/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ This Feature installs the latest .NET SDK, which includes the .NET CLI and the s
1515

1616
| Options Id | Description | Type | Default Value |
1717
|-----|-----|-----|-----|
18-
| version | Select or enter a .NET SDK version. Use 'latest' for the latest version, 'lts' for the latest LTS version, 'X.Y' or 'X.Y.Z' for a specific version. | string | latest |
19-
| additionalVersions | Enter additional .NET SDK versions, separated by commas. Use 'latest' for the latest version, 'lts' for the latest LTS version, 'X.Y' or 'X.Y.Z' for a specific version. | string | - |
20-
| dotnetRuntimeVersions | Enter additional .NET runtime versions, separated by commas. Use 'latest' for the latest version, 'lts' for the latest LTS version, 'X.Y' or 'X.Y.Z' for a specific version. | string | - |
21-
| aspNetCoreRuntimeVersions | Enter additional ASP.NET Core runtime versions, separated by commas. Use 'latest' for the latest version, 'lts' for the latest LTS version, 'X.Y' or 'X.Y.Z' for a specific version. | string | - |
18+
| version | Select or enter a .NET SDK version. Use 'latest' for the latest version, 'lts' for the latest LTS version, 'X.Y' or 'X.Y.Z' for a specific version, 'X.Y-preview' or 'X.Y-daily' for prereleases. | string | latest |
19+
| additionalVersions | Enter additional .NET SDK versions, separated by commas. Use 'latest' for the latest version, 'lts' for the latest LTS version, 'X.Y' or 'X.Y.Z' for a specific version, 'X.Y-preview' or 'X.Y-daily' for prereleases. | string | - |
20+
| dotnetRuntimeVersions | Enter additional .NET runtime versions, separated by commas. Use 'latest' for the latest version, 'lts' for the latest LTS version, 'X.Y' or 'X.Y.Z' for a specific version, 'X.Y-preview' or 'X.Y-daily' for prereleases. | string | - |
21+
| aspNetCoreRuntimeVersions | Enter additional ASP.NET Core runtime versions, separated by commas. Use 'latest' for the latest version, 'lts' for the latest LTS version, 'X.Y' or 'X.Y.Z' for a specific version, 'X.Y-preview' or 'X.Y-daily' for prereleases. | string | - |
2222
| workloads | Enter additional .NET SDK workloads, separated by commas. Use 'dotnet workload search' to learn what workloads are available to install. | string | - |
2323

2424
## Customizations
@@ -95,7 +95,7 @@ Installing .NET workloads. Multiple workloads can be specified as comma-separate
9595
``` json
9696
"features": {
9797
"ghcr.io/devcontainers/features/dotnet:2": {
98-
"workloads": "aspire, wasm-tools"
98+
"workloads": "wasm-tools"
9999
}
100100
}
101101
```

src/dotnet/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ done
105105

106106
# Install .NET versions and dependencies
107107
# icu-devtools includes dependencies for .NET
108-
check_packages wget ca-certificates icu-devtools
108+
check_packages wget ca-certificates icu-devtools jq
109109

110110
for version in "${versions[@]}"; do
111111
read -r clean_version quality < <(parse_version_and_quality "$version")

src/dotnet/scripts/dotnet-helpers.sh

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,49 @@
88
# Maintainer: The Dev Container spec maintainers
99
DOTNET_SCRIPTS=$(dirname "${BASH_SOURCE[0]}")
1010
DOTNET_INSTALL_SCRIPT="$DOTNET_SCRIPTS/vendor/dotnet-install.sh"
11+
DOTNET_RELEASES_INDEX_URL="https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json"
1112

12-
# Prints the latest dotnet version in the specified channel
13-
# Usage: fetch_latest_version_in_channel <channel> [<runtime>]
14-
# Example: fetch_latest_version_in_channel "LTS"
15-
# Example: fetch_latest_version_in_channel "6.0" "dotnet"
16-
# Example: fetch_latest_version_in_channel "6.0" "aspnetcore"
17-
fetch_latest_version_in_channel() {
18-
local channel="$1"
19-
local runtime="$2"
20-
if [ "$runtime" = "dotnet" ]; then
21-
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Runtime/$channel/latest.version"
22-
elif [ "$runtime" = "aspnetcore" ]; then
23-
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/$channel/latest.version"
24-
else
25-
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Sdk/$channel/latest.version"
26-
fi
27-
}
28-
29-
# Prints the latest dotnet version
30-
# Usage: fetch_latest_version [<runtime>]
13+
# Prints the latest active dotnet version from the releases index.
14+
# Usage: fetch_latest_version [<target>]
15+
# With no target, resolves the latest SDK version.
16+
# With "sdk", resolves the latest SDK version explicitly.
17+
# With "dotnet" or "aspnetcore", resolves the latest runtime version.
18+
# Note: the upstream releases index only distinguishes SDK vs runtime for
19+
# latest resolution, so "dotnet" and "aspnetcore" currently resolve to the
20+
# same version.
3121
# Example: fetch_latest_version
22+
# Example: fetch_latest_version "sdk"
3223
# Example: fetch_latest_version "dotnet"
3324
# Example: fetch_latest_version "aspnetcore"
3425
fetch_latest_version() {
35-
local runtime="$1"
36-
local sts_version
37-
local lts_version
38-
sts_version=$(fetch_latest_version_in_channel "STS" "$runtime")
39-
lts_version=$(fetch_latest_version_in_channel "LTS" "$runtime")
40-
if [[ "$sts_version" > "$lts_version" ]]; then
41-
echo "$sts_version"
42-
else
43-
echo "$lts_version"
44-
fi
26+
local target="$1"
27+
local version_field=""
28+
local releases_index=""
29+
30+
case "$target" in
31+
""|sdk)
32+
version_field="latest-sdk"
33+
;;
34+
dotnet|aspnetcore)
35+
version_field="latest-runtime"
36+
;;
37+
*)
38+
echo "Unsupported target '$target'. Expected 'sdk', 'dotnet', or 'aspnetcore'." >&2
39+
return 1
40+
;;
41+
esac
42+
43+
releases_index="$(wget -qO- "$DOTNET_RELEASES_INDEX_URL")" || return $?
44+
45+
printf '%s\n' "$releases_index" \
46+
| jq -er --arg version_field "$version_field" '
47+
.["releases-index"]
48+
| map(
49+
select(."support-phase" == "active")
50+
| .[$version_field]
51+
)
52+
| .[0]
53+
'
4554
}
4655

4756
# Installs a version of the .NET SDK

test/dotnet/dotnet_helpers.sh

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,7 @@
11
#!/bin/bash
22

3-
# Prints the latest dotnet version in the specified channel
4-
# Usage: fetch_latest_version_in_channel <channel> [<runtime>]
5-
# Example: fetch_latest_version_in_channel "LTS"
6-
# Example: fetch_latest_version_in_channel "6.0" "dotnet"
7-
# Example: fetch_latest_version_in_channel "6.0" "aspnetcore"
8-
fetch_latest_version_in_channel() {
9-
local channel="$1"
10-
local runtime="$2"
11-
if [ "$runtime" = "dotnet" ]; then
12-
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Runtime/$channel/latest.version"
13-
elif [ "$runtime" = "aspnetcore" ]; then
14-
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/aspnetcore/Runtime/$channel/latest.version"
15-
else
16-
wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Sdk/$channel/latest.version"
17-
fi
18-
}
19-
20-
# Prints the latest dotnet version
21-
# Usage: fetch_latest_version [<runtime>]
22-
# Example: fetch_latest_version
23-
# Example: fetch_latest_version "dotnet"
24-
# Example: fetch_latest_version "aspnetcore"
25-
fetch_latest_version() {
26-
local runtime="$1"
27-
local sts_version
28-
local lts_version
29-
sts_version=$(fetch_latest_version_in_channel "STS" "$runtime")
30-
lts_version=$(fetch_latest_version_in_channel "LTS" "$runtime")
31-
if [[ "$sts_version" > "$lts_version" ]]; then
32-
echo "$sts_version"
33-
else
34-
echo "$lts_version"
35-
fi
36-
}
3+
# Include the same helper functions used by the install script
4+
source ".devcontainer/dotnet/scripts/dotnet-helpers.sh"
375

386
# Asserts that the specified .NET SDK version is installed
397
# Returns a non-zero exit code if the check fails

test/dotnet/install_dotnet_lts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ source dev-container-features-test-lib
1313
source dotnet_env.sh
1414
source dotnet_helpers.sh
1515

16-
expected=$(fetch_latest_version_in_channel "LTS")
16+
expected=$(wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Sdk/LTS/latest.version")
1717

1818
check "Latest LTS version installed" \
1919
is_dotnet_sdk_version_installed "$expected"

test/dotnet/install_dotnet_specific_release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ source dev-container-features-test-lib
1313
source dotnet_env.sh
1414
source dotnet_helpers.sh
1515

16-
expected=$(fetch_latest_version_in_channel "10.0")
16+
expected=$(wget -qO- "https://builds.dotnet.microsoft.com/dotnet/Sdk/10.0/latest.version")
1717

1818
check ".NET Core SDK 10.0 installed" \
1919
is_dotnet_sdk_version_installed "$expected"

test/dotnet/install_dotnet_workloads.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ source dev-container-features-test-lib
1313
source dotnet_env.sh
1414
source dotnet_helpers.sh
1515

16-
check "Aspire is installed" \
17-
is_dotnet_workload_installed "aspire"
18-
1916
check "WASM tools are installed" \
2017
is_dotnet_workload_installed "wasm-tools"
2118

test/dotnet/scenarios.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"features": {
9090
"dotnet": {
9191
"version": "latest",
92-
"workloads": "aspire, wasm-tools"
92+
"workloads": "wasm-tools"
9393
}
9494
}
9595
}

0 commit comments

Comments
 (0)