diff --git a/src/dotnetaspire/README.md b/src/dotnetaspire/README.md new file mode 100644 index 000000000..8f6f88e0f --- /dev/null +++ b/src/dotnetaspire/README.md @@ -0,0 +1,64 @@ + +# .NET Aspire (dotnetaspire) + +This Feature installs .NET Aspire and if necessary the .NET (dotnet) that it depends on. Options are provided to choose a different version or additional versions. + +## OS Support + +This Feature should work on recent versions of Debian/Ubuntu-based distributions that support .NET and have the `apt` package manager installed + +`bash` is required to execute the `install.sh` script. + +## Example Usage + +```json +"features": { + "ghcr.io/devcontainers/features/dotnetaspire:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | .NET Aspire version. Use 'latest' for the latest supported version, '9.0' for the 9.0 version, 'X.Y' or 'X.Y.Z' for a specific version, or 'latest-daily' for the latest unsupported build. | string | latest | + +## Customizations + +### VS Code Extensions + +- `ms-dotnettools.csdevkit` + +## Configuration examples + +Installing only the latest .NET Aspire version (the default). + +``` jsonc +"features": { + "ghcr.io/devcontainers/features/dotnetaspire:1": "latest" // or "" or {} +} +``` + +Installing .NET Aspire version 9.0. + +``` jsonc +"features": { + "ghcr.io/devcontainers/features/dotnetaspire:1": "9.0" // or "" or {} +} +``` + +Installing the latest .NET Aspire unsupported build. + +``` jsonc +"features": { + "ghcr.io/devcontainers/features/dotnetaspire:1": "latest-daily" // or "" or {} +} +``` + + +## OS Support + +This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed. + +`bash` is required to execute the `install.sh` script. + diff --git a/src/dotnetaspire/devcontainer-feature.json b/src/dotnetaspire/devcontainer-feature.json new file mode 100644 index 000000000..5c5f0caad --- /dev/null +++ b/src/dotnetaspire/devcontainer-feature.json @@ -0,0 +1,42 @@ +{ + "id": "dotnetaspire", + "version": "1.0.0", + "name": ".NET Aspire", + "documentationURL": "https://github.com/devcontainers/features/tree/main/src/dotnetaspire", + "description": "Installs .NET Aspire. See https://aka.ms/dotnetaspire", + "options": { + "version": { + "type": "string", + "proposals": [ + "latest daily", + "latest", + "9.0", + ], + "default": "9.0", + "description": "Select or enter a .NET Aspire version. Use 'latest' for the latest supported version, '9.0' for the 9.0 version, 'X.Y' or 'X.Y.Z' for a specific version, or 'latest-daily' for the latest unsupported build." + }, + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-dotnettools.csdevkit", + "ms-azuretools.vscode-bicep", + "GitHub.copilot-chat", + "GitHub.copilot" + ], + "settings": { + "remote.autoForwardPorts": true, + "remote.autoForwardPortsSource": "hybrid", + "remote.otherPortsAttributes": { + "onAutoForward": "ignore" + } + } + } + }, + "dependsOn": { + "ghcr.io/devcontainers/features/dotnet": { + "version": "8.0", + "additionalVersions": "9.0" + } + } +} diff --git a/src/dotnetaspire/install.sh b/src/dotnetaspire/install.sh new file mode 100644 index 000000000..ac8bf346f --- /dev/null +++ b/src/dotnetaspire/install.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +# Docs: https://github.com/devcontainers/features/tree/main/src/dotnet +# Maintainer: The .NET Aspire team at https://github.com/dotnet/aspire + +set -e + +# default to latest if not specified +VERSION="${VERSION:-"latest"}" + +if [[ ! $VERSION =~ ^(9\.0|latest|latest-daily)$ ]]; then + echo "Error: VERSION must be either '9.0', '9.0.0', 'latest', or 'latest-daily' not: '$VERSION'." + exit 1 +fi + +if [[ $VERSION =~ ^(9\.0|9\.0\.0|latest)$ ]]; then + VERSION="9.0.0" +fi + +echo "Activating feature '.NET Aspire' version: $VERSION" + +# Before .NET Aspire 9.0 install required `dotnet workload`: this is no longer necessary, as Aspire is +# installed when restoring Aspire projects. It's only necessary to install the appropriate version of the templates. + + +if [[ $VERSION =~ ^(9\.0\.0)$ ]]; then + dotnet new install Aspire.ProjectTemplates::$VERSION +else + # https://github.com/dotnet/aspire/blob/main/docs/using-latest-daily.md + dotnet nuget add source --name dotnet9 https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json + + # If you use Package Source Mapping, you'll also need to add the following mappings to your NuGet.config + # + # + # + # + # + # + # + + dotnet new install Aspire.ProjectTemplates::*-* --force +fi + +echo "... done activating feature '.NET Aspire' version: $VERSION" diff --git a/test/dotnetaspire/dotnet_env.sh b/test/dotnetaspire/dotnet_env.sh new file mode 100644 index 000000000..37b14ea2b --- /dev/null +++ b/test/dotnetaspire/dotnet_env.sh @@ -0,0 +1,4 @@ +#!/bin/bash +export DOTNET_NOLOGO=true +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true +export DOTNET_GENERATE_ASPNET_CERTIFICATE=false \ No newline at end of file diff --git a/test/dotnetaspire/install_dotnetaspire_exact_version.sh b/test/dotnetaspire/install_dotnetaspire_exact_version.sh new file mode 100644 index 000000000..f1f641af1 --- /dev/null +++ b/test/dotnetaspire/install_dotnetaspire_exact_version.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/test/dotnetaspire/install_dotnetaspire_latest_daily_version.sh b/test/dotnetaspire/install_dotnetaspire_latest_daily_version.sh new file mode 100644 index 000000000..f1f641af1 --- /dev/null +++ b/test/dotnetaspire/install_dotnetaspire_latest_daily_version.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/test/dotnetaspire/install_dotnetaspire_latest_version.sh b/test/dotnetaspire/install_dotnetaspire_latest_version.sh new file mode 100644 index 000000000..f1f641af1 --- /dev/null +++ b/test/dotnetaspire/install_dotnetaspire_latest_version.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/test/dotnetaspire/scenarios.json b/test/dotnetaspire/scenarios.json new file mode 100644 index 000000000..8865d542a --- /dev/null +++ b/test/dotnetaspire/scenarios.json @@ -0,0 +1,26 @@ +{ + "install_dotnetaspire_exact_version": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "dotnetaspire": { + "version": "9.0" + } + } + }, + "install_dotnetaspire_latest_version": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "dotnetaspire": { + "version": "latest" + } + } + }, + "install_dotnetaspire_latest_daily_version": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "dotnetaspire": { + "version": "latest-daily" + } + } + } +} \ No newline at end of file diff --git a/test/dotnetaspire/test.sh b/test/dotnetaspire/test.sh new file mode 100644 index 000000000..dd421e321 --- /dev/null +++ b/test/dotnetaspire/test.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -e + +# Run tests with `devcontainer features test -f dotnetaspire` in the parent of the src and test folders. + +source dev-container-features-test-lib +source dotnet_env.sh + +check "dotnet is installed in DOTNET_ROOT and execute permission is granted" \ +test -x "$DOTNET_ROOT/dotnet" + +check "dotnet 8.0 is installed" \ +test "$($DOTNET_ROOT/dotnet --info | grep '8.0.')" + +check "dotnet 9.0 is installed" \ +test "$($DOTNET_ROOT/dotnet --info | grep '9.0.')" + +check "dotnetaspire templates are installed" \ +test "$DOTNET_ROOT/dotnet new aspire" + +# There isn't currently a good way to check what version of the templates was installed. + +reportResults \ No newline at end of file