Skip to content

Commit 3948315

Browse files
committed
Add dotnet support
1 parent aaf6ad0 commit 3948315

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,20 @@ RUN for v in $GO_VERSIONS; do mise install "go@${v}"; done \
251251
&& mise cache clear || true \
252252
&& rm -rf "$HOME/.cache/mise" "$HOME/.local/share/mise/downloads"
253253

254+
### DOTNET ###
255+
256+
ARG DOTNET_CHANNELS="9.0 8.0 6.0"
257+
ENV DOTNET_ROOT=/usr/share/dotnet
258+
ENV PATH=$DOTNET_ROOT:$PATH
259+
RUN DOTNET_INSTALL_SCRIPT=$(mktemp) \
260+
&& curl -sSL https://dot.net/v1/dotnet-install.sh -o "$DOTNET_INSTALL_SCRIPT" \
261+
&& chmod +x "$DOTNET_INSTALL_SCRIPT" \
262+
&& for channel in $DOTNET_CHANNELS; do \
263+
"$DOTNET_INSTALL_SCRIPT" --channel "$channel" --install-dir "$DOTNET_ROOT" --no-path; \
264+
done \
265+
&& ln -sf "$DOTNET_ROOT/dotnet" /usr/local/bin/dotnet \
266+
&& rm -f "$DOTNET_INSTALL_SCRIPT"
267+
254268
### PHP ###
255269

256270
ARG PHP_VERSIONS="8.4 8.3 8.2"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The following environment variables can be set to configure runtime installation
5353
| `CODEX_ENV_SWIFT_VERSION` | Swift version to install | `5.10`, `6.1`, `6.2` | |
5454
| `CODEX_ENV_RUBY_VERSION` | Ruby version to install | `3.2.3`, `3.3.8`, `3.4.4` | |
5555
| `CODEX_ENV_PHP_VERSION` | PHP version to install | `8.4`, `8.3`, `8.2` | |
56+
| `CODEX_ENV_DOTNET_VERSION` | .NET SDK channel/version to install | `6.0`, `8.0`, `9.0` | Installs requested SDK into `~/.dotnet/<version>` |
5657

5758

5859

@@ -62,6 +63,7 @@ In addition to the packages specified in the table above, the following packages
6263

6364
- `bun`: 1.2.10
6465
- `java`: 21
66+
- `.NET SDKs`: 9.0, 8.0, 6.0
6567
- `bazelisk` / `bazel`
6668
- `erlang`: 27.1.2
6769
- `elixir`: 1.18.3

setup_universal.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ CODEX_ENV_RUST_VERSION=${CODEX_ENV_RUST_VERSION:-}
99
CODEX_ENV_GO_VERSION=${CODEX_ENV_GO_VERSION:-}
1010
CODEX_ENV_SWIFT_VERSION=${CODEX_ENV_SWIFT_VERSION:-}
1111
CODEX_ENV_PHP_VERSION=${CODEX_ENV_PHP_VERSION:-}
12+
CODEX_ENV_DOTNET_VERSION=${CODEX_ENV_DOTNET_VERSION:-}
13+
14+
DEFAULT_DOTNET_ROOT=${DOTNET_ROOT:-/usr/share/dotnet}
1215

1316
echo "Configuring language runtimes..."
1417

@@ -73,3 +76,45 @@ if [ -n "${CODEX_ENV_PHP_VERSION}" ]; then
7376
mise use --global "php@${CODEX_ENV_PHP_VERSION}"
7477
fi
7578
fi
79+
80+
if [ -n "${CODEX_ENV_DOTNET_VERSION}" ]; then
81+
desired="${CODEX_ENV_DOTNET_VERSION}"
82+
current_sdk=$(dotnet --list-sdks | awk 'NR==1 {print $1}')
83+
echo "# .NET SDK: ${desired} (default: ${current_sdk:-none})"
84+
85+
custom_root="${HOME}/.dotnet/${desired}"
86+
mkdir -p "${custom_root}"
87+
88+
install_args=()
89+
match_pattern="^${desired}"
90+
if [[ "${desired}" =~ ^[0-9]+\.[0-9]+$ ]]; then
91+
install_args=(--channel "${desired}")
92+
match_pattern="^${desired}\."
93+
else
94+
install_args=(--version "${desired}")
95+
fi
96+
97+
needs_install=1
98+
if [ -x "${custom_root}/dotnet" ]; then
99+
if "${custom_root}/dotnet" --list-sdks | awk '{print $1}' | grep -Eq "${match_pattern}"; then
100+
needs_install=0
101+
fi
102+
fi
103+
104+
if [ "${needs_install}" -eq 1 ]; then
105+
tmp_script=$(mktemp)
106+
curl -sSL https://dot.net/v1/dotnet-install.sh -o "${tmp_script}"
107+
chmod +x "${tmp_script}"
108+
"${tmp_script}" "${install_args[@]}" --install-dir "${custom_root}" --no-path
109+
rm -f "${tmp_script}"
110+
fi
111+
112+
export DOTNET_ROOT="${custom_root}"
113+
export DOTNET_MULTILEVEL_LOOKUP=0
114+
case ":${PATH}:" in
115+
*:"${DOTNET_ROOT}":*) ;;
116+
*) export PATH="${DOTNET_ROOT}:${PATH}" ;;
117+
esac
118+
else
119+
export DOTNET_ROOT="${DEFAULT_DOTNET_ROOT}"
120+
fi

verify.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ cargo --version
4242
echo "- Go:"
4343
go version
4444

45+
echo "- .NET:"
46+
dotnet --version
47+
dotnet --list-sdks
48+
4549
echo "- PHP:"
4650
php --version
4751
composer --version

0 commit comments

Comments
 (0)