|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -DOTNET_RELEASES_INDEX_URL="https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json" |
4 | | - |
5 | | -# Prints the latest active dotnet version from the releases index. |
6 | | -# Usage: fetch_latest_version [<target>] |
7 | | -# With no target, resolves the latest SDK version. |
8 | | -# With "sdk", resolves the latest SDK version explicitly. |
9 | | -# With "dotnet" or "aspnetcore", resolves the latest runtime version. |
10 | | -# Note: the upstream releases index only distinguishes SDK vs runtime for |
11 | | -# latest resolution, so "dotnet" and "aspnetcore" currently resolve to the |
12 | | -# same version. |
13 | | -# Example: fetch_latest_version |
14 | | -# Example: fetch_latest_version "sdk" |
15 | | -# Example: fetch_latest_version "dotnet" |
16 | | -# Example: fetch_latest_version "aspnetcore" |
17 | | -fetch_latest_version() { |
18 | | - local target="$1" |
19 | | - local version_field="" |
20 | | - local releases_index="" |
21 | | - |
22 | | - case "$target" in |
23 | | - ""|sdk) |
24 | | - version_field="latest-sdk" |
25 | | - ;; |
26 | | - dotnet|aspnetcore) |
27 | | - version_field="latest-runtime" |
28 | | - ;; |
29 | | - *) |
30 | | - echo "Unsupported target '$target'. Expected 'sdk', 'dotnet', or 'aspnetcore'." >&2 |
31 | | - return 1 |
32 | | - ;; |
33 | | - esac |
34 | | - |
35 | | - releases_index="$(wget -qO- "$DOTNET_RELEASES_INDEX_URL")" || return $? |
36 | | - |
37 | | - printf '%s\n' "$releases_index" \ |
38 | | - | jq -er --arg version_field "$version_field" ' |
39 | | - .["releases-index"] |
40 | | - | map( |
41 | | - select(."support-phase" == "active") |
42 | | - | .[$version_field] |
43 | | - ) |
44 | | - | .[0] |
45 | | - ' |
46 | | -} |
| 3 | +# Include the same helper functions used by the install script |
| 4 | +source ".devcontainer/dotnet/scripts/dotnet-helpers.sh" |
47 | 5 |
|
48 | 6 | # Asserts that the specified .NET SDK version is installed |
49 | 7 | # Returns a non-zero exit code if the check fails |
|
0 commit comments