Skip to content

Commit 05a4cbf

Browse files
authored
dotnet: make 'dotnet' available to 'sudo' commands (#1007)
* dotnet: use predefined DOTNET_ROOT in install script * dotnet: create symbolic link in /usr/bin * dotnet: bump patch version * dotnet: add test for install dir and symlink * Remove unneeded --force
1 parent 1045404 commit 05a4cbf

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/dotnet/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "dotnet",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"name": "Dotnet CLI",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/dotnet",
66
"description": "This Feature installs the latest .NET SDK, which includes the .NET CLI and the shared runtime. Options are provided to choose a different version or additional versions.",

src/dotnet/install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ if [ ${#workloads[@]} -ne 0 ]; then
128128
install_workloads "${workloads[@]}"
129129
fi
130130

131+
# Create a symbolic link '/usr/bin/dotnet', to make dotnet available to 'sudo'
132+
# This is necessary because 'sudo' resets the PATH variable, so it won't search the DOTNET_ROOT directory
133+
if [ ! -e /usr/bin/dotnet ]; then
134+
ln --symbolic "$DOTNET_ROOT/dotnet" /usr/bin/dotnet
135+
fi
136+
131137
# Clean up
132138
rm -rf /var/lib/apt/lists/*
133139
rm -rf scripts

src/dotnet/scripts/dotnet-helpers.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
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_INSTALL_DIR='/usr/share/dotnet'
1211

1312
# Prints the latest dotnet version in the specified channel
1413
# Usage: fetch_latest_version_in_channel <channel> [<runtime>]
@@ -75,11 +74,11 @@ install_sdk() {
7574
fi
7675

7776
# Currently this script does not make it possible to qualify the version, 'GA' is always implied
78-
echo "Executing $DOTNET_INSTALL_SCRIPT --version $version --channel $channel --install-dir $DOTNET_INSTALL_DIR"
77+
echo "Executing $DOTNET_INSTALL_SCRIPT --version $version --channel $channel --install-dir $DOTNET_ROOT"
7978
"$DOTNET_INSTALL_SCRIPT" \
8079
--version "$version" \
8180
--channel "$channel" \
82-
--install-dir "$DOTNET_INSTALL_DIR"
81+
--install-dir "$DOTNET_ROOT"
8382
}
8483

8584
# Installs a version of the .NET Runtime
@@ -107,12 +106,12 @@ install_runtime() {
107106
version="$inputVersion"
108107
fi
109108

110-
echo "Executing $DOTNET_INSTALL_SCRIPT --runtime $runtime --version $version --channel $channel --install-dir $DOTNET_INSTALL_DIR --no-path"
109+
echo "Executing $DOTNET_INSTALL_SCRIPT --runtime $runtime --version $version --channel $channel --install-dir $DOTNET_ROOT --no-path"
111110
"$DOTNET_INSTALL_SCRIPT" \
112111
--runtime "$runtime" \
113112
--version "$version" \
114113
--channel "$channel" \
115-
--install-dir "$DOTNET_INSTALL_DIR" \
114+
--install-dir "$DOTNET_ROOT" \
116115
--no-path
117116
}
118117

test/dotnet/test.sh

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

16+
check "dotnet is installed in DOTNET_ROOT and execute permission is granted" \
17+
test -x "$DOTNET_ROOT/dotnet"
18+
19+
check "dotnet is symlinked correctly in /usr/bin" \
20+
test -L /usr/bin/dotnet -a "$(readlink -f /usr/bin/dotnet)" = "$DOTNET_ROOT/dotnet"
21+
1622
expected=$(fetch_latest_version)
1723

1824
check "Latest .NET SDK version installed" \

0 commit comments

Comments
 (0)