Unverified Commit 15320f01 authored by Steven's avatar Steven Committed by GitHub

dotnet: add ability to install workloads (#997)

* dotnet: add ability to install workloads

* Bump dotnet feature version

* Update NOTES instead of README

* Simplify workloads example

* Fix temp-dir path oopsie

* Improve log message

* Fix typo imstalling->installing

* Install all workloads at once, fix DOTNET vars not taking effect
parent 22ee16e2
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
Installing only the latest .NET SDK version (the default). Installing only the latest .NET SDK version (the default).
``` json ``` jsonc
{
"features": { "features": {
"ghcr.io/devcontainers/features/dotnet:2": "latest" // or "" or {} "ghcr.io/devcontainers/features/dotnet:2": "latest" // or "" or {}
} }
...@@ -12,7 +11,6 @@ Installing only the latest .NET SDK version (the default). ...@@ -12,7 +11,6 @@ Installing only the latest .NET SDK version (the default).
Installing an additional SDK version. Multiple versions can be specified as comma-separated values. Installing an additional SDK version. Multiple versions can be specified as comma-separated values.
``` json ``` json
{
"features": { "features": {
"ghcr.io/devcontainers/features/dotnet:2": { "ghcr.io/devcontainers/features/dotnet:2": {
"additionalVersions": "lts" "additionalVersions": "lts"
...@@ -23,7 +21,6 @@ Installing an additional SDK version. Multiple versions can be specified as comm ...@@ -23,7 +21,6 @@ Installing an additional SDK version. Multiple versions can be specified as comm
Installing specific SDK versions. Installing specific SDK versions.
``` json ``` json
{
"features": { "features": {
"ghcr.io/devcontainers/features/dotnet:2": { "ghcr.io/devcontainers/features/dotnet:2": {
"version": "6.0", "version": "6.0",
...@@ -35,7 +32,6 @@ Installing specific SDK versions. ...@@ -35,7 +32,6 @@ Installing specific SDK versions.
Installing a specific SDK feature band. Installing a specific SDK feature band.
``` json ``` json
{
"features": { "features": {
"ghcr.io/devcontainers/features/dotnet:2": { "ghcr.io/devcontainers/features/dotnet:2": {
"version": "6.0.4xx", "version": "6.0.4xx",
...@@ -46,7 +42,6 @@ Installing a specific SDK feature band. ...@@ -46,7 +42,6 @@ Installing a specific SDK feature band.
Installing a specific SDK patch version. Installing a specific SDK patch version.
``` json ``` json
{
"features": { "features": {
"ghcr.io/devcontainers/features/dotnet:2": { "ghcr.io/devcontainers/features/dotnet:2": {
"version": "6.0.412", "version": "6.0.412",
...@@ -57,7 +52,6 @@ Installing a specific SDK patch version. ...@@ -57,7 +52,6 @@ Installing a specific SDK patch version.
Installing only the .NET Runtime or the ASP.NET Core Runtime. (The SDK includes all runtimes so this configuration is only useful if you need to run .NET apps without building them from source.) Installing only the .NET Runtime or the ASP.NET Core Runtime. (The SDK includes all runtimes so this configuration is only useful if you need to run .NET apps without building them from source.)
``` json ``` json
{
"features": { "features": {
"ghcr.io/devcontainers/features/dotnet:2": { "ghcr.io/devcontainers/features/dotnet:2": {
"version": "none", "version": "none",
...@@ -67,6 +61,16 @@ Installing only the .NET Runtime or the ASP.NET Core Runtime. (The SDK includes ...@@ -67,6 +61,16 @@ Installing only the .NET Runtime or the ASP.NET Core Runtime. (The SDK includes
} }
``` ```
Installing .NET workloads. Multiple workloads can be specified as comma-separated values.
``` json
"features": {
"ghcr.io/devcontainers/features/dotnet:2": {
"workloads": "aspire, wasm-tools"
}
}
```
## OS Support ## OS Support
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.
......
{ {
"id": "dotnet", "id": "dotnet",
"version": "2.0.6", "version": "2.1.0",
"name": "Dotnet CLI", "name": "Dotnet CLI",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/dotnet", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/dotnet",
"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.", "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.",
...@@ -32,6 +32,11 @@ ...@@ -32,6 +32,11 @@
"type": "string", "type": "string",
"default": "", "default": "",
"description": "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." "description": "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."
},
"workloads": {
"type": "string",
"default": "",
"description": "Enter additional .NET SDK workloads, separated by commas. Use 'dotnet workload search' to learn what workloads are available to install."
} }
}, },
"containerEnv": { "containerEnv": {
......
...@@ -10,6 +10,14 @@ DOTNET_VERSION="${VERSION:-"latest"}" ...@@ -10,6 +10,14 @@ DOTNET_VERSION="${VERSION:-"latest"}"
ADDITIONAL_VERSIONS="${ADDITIONALVERSIONS:-""}" ADDITIONAL_VERSIONS="${ADDITIONALVERSIONS:-""}"
DOTNET_RUNTIME_VERSIONS="${DOTNETRUNTIMEVERSIONS:-""}" DOTNET_RUNTIME_VERSIONS="${DOTNETRUNTIMEVERSIONS:-""}"
ASPNETCORE_RUNTIME_VERSIONS="${ASPNETCORERUNTIMEVERSIONS:-""}" ASPNETCORE_RUNTIME_VERSIONS="${ASPNETCORERUNTIMEVERSIONS:-""}"
WORKLOADS="${WORKLOADS:-""}"
# Prevent "Welcome to .NET" message from dotnet
export DOTNET_NOLOGO=true
# Prevent generating a development certificate while running this script
# Otherwise it would be stored in the image, which is undesirable
export DOTNET_GENERATE_ASPNET_CERTIFICATE=false
set -e set -e
...@@ -111,6 +119,15 @@ for version in "${aspNetCoreRuntimeVersions[@]}"; do ...@@ -111,6 +119,15 @@ for version in "${aspNetCoreRuntimeVersions[@]}"; do
install_runtime "aspnetcore" "$version" install_runtime "aspnetcore" "$version"
done done
workloads=()
for workload in $(split_csv "$WORKLOADS"); do
workloads+=("$workload")
done
if [ ${#workloads[@]} -ne 0 ]; then
install_workloads "${workloads[@]}"
fi
# Clean up # Clean up
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
rm -rf scripts rm -rf scripts
......
...@@ -25,7 +25,6 @@ fetch_latest_version_in_channel() { ...@@ -25,7 +25,6 @@ fetch_latest_version_in_channel() {
else else
wget -qO- "https://dotnetcli.azureedge.net/dotnet/Sdk/$channel/latest.version" wget -qO- "https://dotnetcli.azureedge.net/dotnet/Sdk/$channel/latest.version"
fi fi
} }
# Prints the latest dotnet version # Prints the latest dotnet version
...@@ -76,12 +75,11 @@ install_sdk() { ...@@ -76,12 +75,11 @@ install_sdk() {
fi fi
# Currently this script does not make it possible to qualify the version, 'GA' is always implied # Currently this script does not make it possible to qualify the version, 'GA' is always implied
echo "Executing $DOTNET_INSTALL_SCRIPT --version $version --channel $channel --install-dir $DOTNET_INSTALL_DIR --no-path" echo "Executing $DOTNET_INSTALL_SCRIPT --version $version --channel $channel --install-dir $DOTNET_INSTALL_DIR"
"$DOTNET_INSTALL_SCRIPT" \ "$DOTNET_INSTALL_SCRIPT" \
--version "$version" \ --version "$version" \
--channel "$channel" \ --channel "$channel" \
--install-dir "$DOTNET_INSTALL_DIR" \ --install-dir "$DOTNET_INSTALL_DIR"
--no-path
} }
# Installs a version of the .NET Runtime # Installs a version of the .NET Runtime
...@@ -117,3 +115,16 @@ install_runtime() { ...@@ -117,3 +115,16 @@ install_runtime() {
--install-dir "$DOTNET_INSTALL_DIR" \ --install-dir "$DOTNET_INSTALL_DIR" \
--no-path --no-path
} }
# Installs one or more .NET workloads
# Usage: install_workload <workload_id> [<workload_id> ...]
# Reference: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-workload-install
install_workloads() {
local workloads="$@"
echo "Installing .NET workload(s) $workloads"
dotnet workload install $workloads --temp-dir /tmp/dotnet-workload-temp-dir
# Clean up
rm -r /tmp/dotnet-workload-temp-dir
}
...@@ -15,7 +15,6 @@ fetch_latest_version_in_channel() { ...@@ -15,7 +15,6 @@ fetch_latest_version_in_channel() {
else else
wget -qO- "https://dotnetcli.azureedge.net/dotnet/Sdk/$channel/latest.version" wget -qO- "https://dotnetcli.azureedge.net/dotnet/Sdk/$channel/latest.version"
fi fi
} }
# Prints the latest dotnet version # Prints the latest dotnet version
...@@ -47,7 +46,6 @@ is_dotnet_sdk_version_installed() { ...@@ -47,7 +46,6 @@ is_dotnet_sdk_version_installed() {
return $? return $?
} }
# Asserts that the specified .NET Runtime version is installed # Asserts that the specified .NET Runtime version is installed
# Returns a non-zero exit code if the check fails # Returns a non-zero exit code if the check fails
# Usage: is_dotnet_runtime_version_installed <version> # Usage: is_dotnet_runtime_version_installed <version>
...@@ -68,4 +66,14 @@ is_aspnetcore_runtime_version_installed() { ...@@ -68,4 +66,14 @@ is_aspnetcore_runtime_version_installed() {
local expected="$1" local expected="$1"
dotnet --list-runtimes | grep --fixed-strings --silent "Microsoft.AspNetCore.App $expected" dotnet --list-runtimes | grep --fixed-strings --silent "Microsoft.AspNetCore.App $expected"
return $? return $?
} }
\ No newline at end of file
# Asserts that the specified workload is installed
# Returns a non-zero exit code if the check fails
# Usage: is_dotnet_workload_installed <workload_id>
# Example: is_dotnet_workload_installed "aspire"
is_dotnet_workload_installed() {
local expected="$1"
dotnet workload list | grep --fixed-strings --silent "$expected"
return $?
}
#!/bin/bash
set -e
# Optional: Import test library bundled with the devcontainer CLI
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
# Provides the 'check' and 'reportResults' commands.
source dev-container-features-test-lib
# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
source dotnet_env.sh
source dotnet_helpers.sh
check "Aspire is installed" \
is_dotnet_workload_installed "aspire"
check "WASM tools are installed" \
is_dotnet_workload_installed "wasm-tools"
# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
...@@ -81,5 +81,15 @@ ...@@ -81,5 +81,15 @@
"aspnetcoreRuntimeVersions": "latest" "aspnetcoreRuntimeVersions": "latest"
} }
} }
},
"install_dotnet_workloads": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"remoteUser": "vscode",
"features": {
"dotnet": {
"version": "latest",
"workloads": "aspire, wasm-tools"
}
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment