Skip to content

Commit 0742173

Browse files
[ubuntu] Modify installation and add .NET 9 (#13004)
1 parent b1634b1 commit 0742173

File tree

3 files changed

+36
-66
lines changed

3 files changed

+36
-66
lines changed

images/ubuntu/scripts/build/install-dotnetcore-sdk.sh

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,83 +9,59 @@ source $HELPER_SCRIPTS/etc-environment.sh
99
source $HELPER_SCRIPTS/install.sh
1010
source $HELPER_SCRIPTS/os.sh
1111

12-
extract_dotnet_sdk() {
13-
local archive_name=$1
14-
15-
set -e
16-
destination="./tmp-$(basename -s .tar.gz $archive_name)"
17-
18-
echo "Extracting $archive_name to $destination"
19-
mkdir "$destination" && tar -C "$destination" -xzf "$archive_name"
20-
rsync -qav --remove-source-files "$destination/shared/" /usr/share/dotnet/shared/
21-
rsync -qav --remove-source-files "$destination/host/" /usr/share/dotnet/host/
22-
rsync -qav --remove-source-files "$destination/sdk/" /usr/share/dotnet/sdk/
23-
rm -rf "$destination" "$archive_name"
24-
}
25-
26-
# Ubuntu 20 doesn't support EOL versions
27-
latest_dotnet_packages=$(get_toolset_value '.dotnet.aptPackages[]')
2812
dotnet_versions=$(get_toolset_value '.dotnet.versions[]')
2913
dotnet_tools=$(get_toolset_value '.dotnet.tools[].name')
3014

3115
# Disable telemetry
3216
export DOTNET_CLI_TELEMETRY_OPTOUT=1
3317

34-
# Install .NET SDK from apt
35-
# There is a versions conflict, that leads to
36-
# Microsoft <-> Canonical repos dependencies mix up.
37-
# Give Microsoft's repo higher priority to avoid collisions.
38-
# See: https://github.com/dotnet/core/issues/7699
39-
cat << EOF > /etc/apt/preferences.d/dotnet
40-
Package: *net*
41-
Pin: origin packages.microsoft.com
42-
Pin-Priority: 1001
43-
EOF
44-
45-
apt-get update
46-
47-
for latest_package in ${latest_dotnet_packages[@]}; do
48-
echo "Determining if .NET Core ($latest_package) is installed"
49-
if ! dpkg -S $latest_package &> /dev/null; then
50-
echo "Could not find .NET Core ($latest_package), installing..."
51-
apt-get install $latest_package
52-
else
53-
echo ".NET Core ($latest_package) is already installed"
54-
fi
55-
done
56-
57-
rm /etc/apt/preferences.d/dotnet
58-
18+
# Install dotnet dependencies
19+
# https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-decision#dependencies
5920
apt-get update
21+
apt-get install --no-install-recommends \
22+
ca-certificates \
23+
libc6 \
24+
libgcc-s1 \
25+
libgssapi-krb5-2 \
26+
liblttng-ust1 \
27+
libssl3 \
28+
libstdc++6 \
29+
zlib1g
30+
31+
if is_ubuntu22; then
32+
apt-get install --no-install-recommends libicu70
33+
fi
34+
35+
if is_ubuntu24; then
36+
apt-get install --no-install-recommends libicu74
37+
fi
38+
39+
# Install .NET SDKs and Runtimes
40+
mkdir -p /usr/share/dotnet
6041

61-
# Install .NET SDK from home repository
62-
# Get list of all released SDKs from channels which are not end-of-life or preview
6342
sdks=()
6443
for version in ${dotnet_versions[@]}; do
6544
release_url="https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/${version}/releases.json"
6645
releases=$(cat "$(download_with_retry "$release_url")")
67-
if [[ $version == "6.0" ]]; then
68-
sdks=("${sdks[@]}" $(echo "${releases}" | jq -r 'first(.releases[].sdks[]?.version | select(contains("preview") or contains("rc") | not))'))
69-
else
70-
sdks=("${sdks[@]}" $(echo "${releases}" | jq -r '.releases[].sdk.version | select(contains("preview") or contains("rc") | not)'))
71-
sdks=("${sdks[@]}" $(echo "${releases}" | jq -r '.releases[].sdks[]?.version | select(contains("preview") or contains("rc") | not)'))
72-
fi
46+
sdks=("${sdks[@]}" $(echo "${releases}" | jq -r '.releases[].sdk.version | select(contains("preview") or contains("rc") | not)'))
47+
sdks=("${sdks[@]}" $(echo "${releases}" | jq -r '.releases[].sdks[]?.version | select(contains("preview") or contains("rc") | not)'))
7348
done
7449

7550
sorted_sdks=$(echo ${sdks[@]} | tr ' ' '\n' | sort -r | uniq -w 5)
7651

77-
# Download/install additional SDKs in parallel
78-
export -f download_with_retry
79-
export -f extract_dotnet_sdk
52+
## Download installer from dot.net
53+
DOTNET_INSTALL_SCRIPT="https://dot.net/v1/dotnet-install.sh"
54+
install_script_path=$(download_with_retry $DOTNET_INSTALL_SCRIPT)
55+
chmod +x $install_script_path
8056

81-
parallel --jobs 0 --halt soon,fail=1 \
82-
'url="https://dotnetcli.blob.core.windows.net/dotnet/Sdk/{}/dotnet-sdk-{}-linux-x64.tar.gz"; \
83-
download_with_retry $url' ::: "${sorted_sdks[@]}"
57+
for sdk in ${sorted_sdks[@]}; do
58+
echo "Installing .NET SDK $sdk"
59+
$install_script_path --version $sdk --install-dir /usr/share/dotnet --no-path
60+
done
8461

85-
find . -name "*.tar.gz" | parallel --halt soon,fail=1 'extract_dotnet_sdk {}'
62+
## Dotnet installer doesn't create symlinks to executable or modify PATH
63+
ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
8664

87-
# NuGetFallbackFolder at /usr/share/dotnet/sdk/NuGetFallbackFolder is warmed up by smoke test
88-
# Additional FTE will just copy to ~/.dotnet/NuGet which provides no benefit on a fungible machine
8965
set_etc_environment_variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE 1
9066
set_etc_environment_variable DOTNET_NOLOGO 1
9167
set_etc_environment_variable DOTNET_MULTILEVEL_LOOKUP 0

images/ubuntu/toolsets/toolset-2204.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,6 @@
268268
}
269269
],
270270
"dotnet": {
271-
"aptPackages": [
272-
"dotnet-sdk-8.0",
273-
"dotnet-sdk-9.0"
274-
],
275271
"versions": [
276272
"8.0",
277273
"9.0"

images/ubuntu/toolsets/toolset-2404.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,9 @@
228228
}
229229
],
230230
"dotnet": {
231-
"aptPackages": [
232-
"dotnet-sdk-8.0"
233-
],
234231
"versions": [
235-
"8.0"
232+
"8.0",
233+
"9.0"
236234
],
237235
"tools": [
238236
{ "name": "nbgv", "test": "nbgv --version", "getversion" : "nbgv --version" }

0 commit comments

Comments
 (0)