From ccb4a79bbb69770f1b23addfbf738e0558b308bf Mon Sep 17 00:00:00 2001 From: Kieron Lanning Date: Wed, 18 Nov 2026 18:21:37 +0000 Subject: [PATCH] feat: updated the Aspire detection to work with 17+ --- .config/dotnet-tools.json | 4 +- .editorconfig | 2 +- CHANGELOG.md | 13 +++ README.md | 8 +- docs/wiki/Configuration-Reference.md | 4 +- docs/wiki/Getting-Started.md | 2 +- docs/wiki/concepts/Project-Type-Detection.md | 8 +- package.json | 2 +- .../SKILL.md | 7 +- src/src/BuildSdk/Sdk/Sdk.props | 22 ++++- .../BuildSdk/Sdk/Sdk.props.buildschema.json | 2 +- .../ProjectClassificationTests.cs | 81 +++++++++++++++++++ templates/global.json | 2 +- 13 files changed, 138 insertions(+), 19 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 1978504..ec846e1 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -10,14 +10,14 @@ "rollForward": false }, "dotnet-inspect": { - "version": "0.27.0", + "version": "0.28.0", "commands": [ "dotnet-inspect" ], "rollForward": false }, "purview.build": { - "version": "0.9.1", + "version": "0.9.2", "commands": [ "purview-build" ], diff --git a/.editorconfig b/.editorconfig index b0390ec..e7289fa 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -# Purview.BuildSdk 2.2.0 - managed file, do not edit +# Purview.BuildSdk 2.2.1 - managed file, do not edit # # This file is written by Purview.BuildSdk and is replaced whenever the SDK version changes. The version # on the first line is how the SDK recognises a file it owns: a .editorconfig without that marker is diff --git a/CHANGELOG.md b/CHANGELOG.md index c66fe5d..381a5cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,19 @@ is used only while the version is a pre-release (`-alpha`, `-beta`, `-rc`). This file was reconstructed from the conventional-commit history at 1.0.7, so entries before that release summarise what the commits recorded rather than what was written at the time. +## [2.2.1] - 2026-11-18 + +### Fixed + +- **Aspire 17 AppHost detection.** `IsAspireHostProject` is now also `true` when a project references the + `Aspire.Hosting.AppHost` package, which is the form Aspire 17 uses now that `Aspire.AppHost.Sdk` is + obsolete. The package's own `IsAspireHost` property is not available when this SDK is imported from + `Directory.Build.props` (NuGet package props are imported after that file), so the comment-stripped + project text is scanned for the reference. The legacy `Aspire.Sdk.Host`/`Aspire.AppHost.Sdk` SDK + detection is unchanged, and a package-detected AppHost gets the same `OutputType=Exe`, CA1515 exemption + and `IsAspireProjectResource=false` references as an SDK-based one. A reference declared only in a shared + props file is not detected; set `IsAspireHostProject=true` before the `Sdk.props` import to opt in. + ## [2.2.0] - 2026-11-17 ### Changed (breaking) diff --git a/README.md b/README.md index 7e9bf99..8208315 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ A reusable MSBuild SDK NuGet package that delivers standardised .NET project def "runner": "Microsoft.Testing.Platform" }, "msbuild-sdks": { - "Purview.BuildSdk": "2.2.0" + "Purview.BuildSdk": "2.2.1" } } ``` @@ -238,7 +238,7 @@ to a low-importance message) and only a copy that still fails after every retry The bootstrapped `.editorconfig` opens with a version marker: ```editorconfig -# Purview.BuildSdk 2.2.0 - managed file, do not edit +# Purview.BuildSdk 2.2.1 - managed file, do not edit ``` That line is how the SDK recognises a file **it** wrote. When the SDK version changes, a file carrying @@ -539,7 +539,7 @@ import (or, where noted, in the project). | `IsWebProject` | *(detected from the project)* | Marks a project with web behaviour (a web SDK project or an API host). | | `IsWebSdkProject` | *(detected from the project)* | `true` when the project SDK is `Microsoft.NET.Sdk.Web`. | | `IsWorkerSdkProject` | *(detected from the project)* | `true` when the project SDK is `Microsoft.NET.Sdk.Worker`. | -| `IsAspireHostProject` | *(detected from the project)* | `true` when the project SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`. | +| `IsAspireHostProject` | *(detected from the project)* | `true` when the project SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`, or the project file references `Aspire.Hosting.AppHost` (Aspire 17+). | | `IsBlazorWebAssemblyProject` | *(detected from the project)* | `true` when the project SDK is `Microsoft.NET.Sdk.BlazorWebAssembly`. | | `IsRazorClassLibraryProject` | *(detected from the project)* | `true` when the project SDK is `Microsoft.NET.Sdk.Razor`. | | `IsBlazorHostProject` | *(detected from the project)* | `true` for a web SDK project that references a Blazor WebAssembly client. Says nothing about whether the host is a BFF. | @@ -642,7 +642,7 @@ Read the exported property rather than re-deriving SDK behaviour — it is the S | `IsWebProject` | Marker used in SDK web-project behaviour. | | `IsWebSdkProject` | True when `SdkProjectName` is `Microsoft.NET.Sdk.Web`. | | `IsWorkerSdkProject` | True when `SdkProjectName` is `Microsoft.NET.Sdk.Worker`. | -| `IsAspireHostProject` | True when SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`. | +| `IsAspireHostProject` | True when SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`, or the project references `Aspire.Hosting.AppHost`. | | `IsBlazorWebAssemblyProject` | True when `SdkProjectName` is `Microsoft.NET.Sdk.BlazorWebAssembly`. | | `IsRazorClassLibraryProject` | True when `SdkProjectName` is `Microsoft.NET.Sdk.Razor`. | | `IsBlazorHostProject` | True for a web SDK project that references a Blazor WebAssembly client. | diff --git a/docs/wiki/Configuration-Reference.md b/docs/wiki/Configuration-Reference.md index 8f58cc7..8fde8a3 100644 --- a/docs/wiki/Configuration-Reference.md +++ b/docs/wiki/Configuration-Reference.md @@ -300,7 +300,7 @@ Override one by setting it before the `Sdk.props` import. See [Project Type Dete | `IsWebProject` | *(detected from the project)* | Marks a project with web behaviour (a web SDK project or an API host). | | `IsWebSdkProject` | *(detected from the project)* | `true` when the project SDK is `Microsoft.NET.Sdk.Web`. | | `IsWorkerSdkProject` | *(detected from the project)* | `true` when the project SDK is `Microsoft.NET.Sdk.Worker`. | -| `IsAspireHostProject` | *(detected from the project)* | `true` when the project SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`. | +| `IsAspireHostProject` | *(detected from the project)* | `true` when the project SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`, or the project file references `Aspire.Hosting.AppHost` (Aspire 17+). | | `IsBlazorWebAssemblyProject` | *(detected from the project)* | `true` when the project SDK is `Microsoft.NET.Sdk.BlazorWebAssembly`. | | `IsRazorClassLibraryProject` | *(detected from the project)* | `true` when the project SDK is `Microsoft.NET.Sdk.Razor`. | | `IsBlazorHostProject` | *(detected from the project)* | `true` for a web SDK project that references a Blazor WebAssembly client. Says nothing about whether the host is a BFF. | @@ -407,7 +407,7 @@ property that is not in this list. | `IsWebProject` | Marker used in SDK web-project behaviour. | | `IsWebSdkProject` | True when `SdkProjectName` is `Microsoft.NET.Sdk.Web`. | | `IsWorkerSdkProject` | True when `SdkProjectName` is `Microsoft.NET.Sdk.Worker`. | -| `IsAspireHostProject` | True when SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`. | +| `IsAspireHostProject` | True when SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`, or the project references `Aspire.Hosting.AppHost`. | | `IsBlazorWebAssemblyProject` | True when `SdkProjectName` is `Microsoft.NET.Sdk.BlazorWebAssembly`. | | `IsRazorClassLibraryProject` | True when `SdkProjectName` is `Microsoft.NET.Sdk.Razor`. | | `IsBlazorHostProject` | True for a web SDK project that references a Blazor WebAssembly client. | diff --git a/docs/wiki/Getting-Started.md b/docs/wiki/Getting-Started.md index 397240c..b3639a4 100644 --- a/docs/wiki/Getting-Started.md +++ b/docs/wiki/Getting-Started.md @@ -15,7 +15,7 @@ pinned SDK version — bump it deliberately, because a released version can chan "runner": "Microsoft.Testing.Platform" }, "msbuild-sdks": { - "Purview.BuildSdk": "2.2.0" + "Purview.BuildSdk": "2.2.1" } } ``` diff --git a/docs/wiki/concepts/Project-Type-Detection.md b/docs/wiki/concepts/Project-Type-Detection.md index a1ba2fb..9eafb58 100644 --- a/docs/wiki/concepts/Project-Type-Detection.md +++ b/docs/wiki/concepts/Project-Type-Detection.md @@ -21,7 +21,7 @@ wiki. | `IsSdkProject` | An `Sdk` value is parsed from the ``/`` element. | | `IsWebSdkProject` | `SdkProjectName` is `Microsoft.NET.Sdk.Web`. | | `IsWorkerSdkProject` | `SdkProjectName` is `Microsoft.NET.Sdk.Worker`. | -| `IsAspireHostProject` | `SdkProjectName` starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`. | +| `IsAspireHostProject` | `SdkProjectName` starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`, or the project file references `Aspire.Hosting.AppHost` (Aspire 17+). | | `IsCLIProject` | Project name ends with `CLI`, `Console`, `CommandLine`, `QuickStart`, or `QuickStarts`. | | `IsBlazorWebAssemblyProject` | `SdkProjectName` is `Microsoft.NET.Sdk.BlazorWebAssembly`. | | `IsRazorClassLibraryProject` | `SdkProjectName` is `Microsoft.NET.Sdk.Razor`. | @@ -31,6 +31,12 @@ wiki. | `IsPackable` | `true` is declared in the project file. | | `IsWebProject` | Marker used in SDK web-project behaviour. | +`IsAspireHostProject` also recognises Aspire 17's form: `Microsoft.NET.Sdk` plus an +`Aspire.Hosting.AppHost` `PackageReference`. The reference is read from the project file, because this +SDK is imported from `Directory.Build.props` and NuGet package props are imported after that file. A +reference declared only in a shared props file is not detected; set `IsAspireHostProject=true` in +`Directory.Build.props` before the SDK import to opt in. + `TestingType` is the detected test category suffix from the project name (for example `Unit`, `Integration`, `E2E`); `TargetProjectName` is the inferred non-test project name that a test project targets. The detected `TestingType` also becomes the baseline test category, while additional categories diff --git a/package.json b/package.json index 16f91f7..d1e33a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "build-sdk", - "version": "2.2.0", + "version": "2.2.1", "homepage": "https://purview.dev/projects/build-sdk/", "bugs": { "url": "https://github.com/purview-dev/build-sdk/issues" diff --git a/skills/purview-buildsdk-project-detection/SKILL.md b/skills/purview-buildsdk-project-detection/SKILL.md index a893896..d1198f8 100644 --- a/skills/purview-buildsdk-project-detection/SKILL.md +++ b/skills/purview-buildsdk-project-detection/SKILL.md @@ -71,7 +71,7 @@ classification that decides it. | the project's `Sdk="..."` declaration | `IsSdkProject`, `SdkProjectName` | | `Microsoft.NET.Sdk.Web` | `IsWebSdkProject=true` | | `Microsoft.NET.Sdk.Worker` | `IsWorkerSdkProject=true` | -| SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk` | `IsAspireHostProject=true` | +| SDK starts with `Aspire.Sdk.Host` or `Aspire.AppHost.Sdk`, or the project references `Aspire.Hosting.AppHost` (Aspire 17+) | `IsAspireHostProject=true` | | `Dockerfile`, `dockerfile` or `Dockerfile.dev` in the project directory | `IsContainerProject=true` | | name ends with `CLI`, `Console`, `CommandLine`, `QuickStart`, `QuickStarts` | `IsCLIProject=true` | | `Microsoft.NET.Sdk.BlazorWebAssembly` | `IsBlazorWebAssemblyProject=true` | @@ -79,6 +79,11 @@ classification that decides it. | a web SDK project whose name ends with `Bff` (case-sensitive, like `CLI`), or that sets `IsBffProject=true` | `IsBffProject=true` | | a web SDK project that references an `IsBlazorWebAssemblyProject` project | `IsBlazorHostProject=true` | +`IsAspireHostProject` also matches Aspire 17's form: `Microsoft.NET.Sdk` plus an +`Aspire.Hosting.AppHost` `PackageReference` in the project file. The package's own `IsAspireHost` is +imported after this SDK, so the project file is what is read. A reference declared only in a shared +props file is not detected; set `IsAspireHostProject=true` before the `Sdk.props` import to opt in. + `IsBffProject=false` opts a `*Bff` project out. `IsBlazorHostProject` is **never** inferred into `IsBffProject`: a host that keeps no tokens is not a BFF, and BFF rules do not describe it. diff --git a/src/src/BuildSdk/Sdk/Sdk.props b/src/src/BuildSdk/Sdk/Sdk.props index 9e8593e..40997ca 100644 --- a/src/src/BuildSdk/Sdk/Sdk.props +++ b/src/src/BuildSdk/Sdk/Sdk.props @@ -174,7 +174,9 @@ false false false - false + + false false false false @@ -304,9 +306,21 @@ false + + <_PurviewProjectReferencesAspireAppHost + Condition="$([System.Text.RegularExpressions.Regex]::IsMatch($(_PurviewProjectText), `(?is)<PackageReference\b[^>]*\bInclude\s*=\s*["']Aspire\.Hosting\.AppHost["'][^>]*>`))" + >true true True when SdkProjectName is Microsoft.NET.Sdk.Worker. - True when the project SDK starts with Aspire.Sdk.Host or Aspire.AppHost.Sdk. + True for an Aspire AppHost: the project SDK starts with Aspire.Sdk.Host or Aspire.AppHost.Sdk, or the project references Aspire.Hosting.AppHost (Aspire 17+). True when SdkProjectName is Microsoft.NET.Sdk.BlazorWebAssembly. diff --git a/src/src/BuildSdk/Sdk/Sdk.props.buildschema.json b/src/src/BuildSdk/Sdk/Sdk.props.buildschema.json index 11b9142..719966b 100644 --- a/src/src/BuildSdk/Sdk/Sdk.props.buildschema.json +++ b/src/src/BuildSdk/Sdk/Sdk.props.buildschema.json @@ -138,7 +138,7 @@ "defaultValue": "false" }, "IsAspireHostProject": { - "description": "True when the project SDK starts with Aspire.Sdk.Host or Aspire.AppHost.Sdk. Set it before the `Sdk.props` import to override. No default: detected from the project.", + "description": "True for an Aspire AppHost: the project SDK starts with Aspire.Sdk.Host or Aspire.AppHost.Sdk, or the project file references Aspire.Hosting.AppHost (Aspire 17+). A reference declared only in a shared props file is not detected; set it before the `Sdk.props` import to opt in. No default: detected from the project.", "type": "bool" }, "IsBffProject": { diff --git a/src/tests/BuildSdk.IntegrationTests/ProjectClassificationTests.cs b/src/tests/BuildSdk.IntegrationTests/ProjectClassificationTests.cs index ed82fcb..bde7dad 100644 --- a/src/tests/BuildSdk.IntegrationTests/ProjectClassificationTests.cs +++ b/src/tests/BuildSdk.IntegrationTests/ProjectClassificationTests.cs @@ -150,6 +150,87 @@ public async Task AspireHostProject_DetectedByFileContentMarker(CancellationToke await Assert.That(await h.GetPropertyAsync("IsAspireHostProject", cancellationToken)).IsEqualTo("true"); } + /// + /// Aspire 17 replaced the Aspire.AppHost.Sdk MSBuild SDK with Microsoft.NET.Sdk plus an + /// Aspire.Hosting.AppHost package reference. The package's own IsAspireHost property is + /// imported after this SDK (NuGet package props follow Directory.Build.props), so the project + /// file is scanned for the reference instead. + /// + [Test] + [Arguments("""""")] + [Arguments("""""")] + [Arguments("""""")] + public async Task AspireHostProject_DetectedByAppHostPackageReference( + string packageReference, + CancellationToken cancellationToken + ) + { + using var h = await ProjectHarness.CreateAsync( + "Acme.AppHost", + extraItems: packageReference, + cancellationToken: cancellationToken + ); + var props = await h.GetPropertiesAsync( + cancellationToken, + "IsAspireHostProject", + "OutputType", + "NoWarn", + "PurviewPolicyExemptNoWarn" + ); + + await Assert.That(props["IsAspireHostProject"]).IsEqualTo("true"); + await Assert.That(props["OutputType"]).IsEqualTo("Exe"); + await Assert.That(props["NoWarn"]).Contains("CA1515"); + await Assert.That(props["PurviewPolicyExemptNoWarn"]).Contains("CA1515"); + } + + [Test] + [Arguments("""""")] + [Arguments("""""")] + public async Task AspireHostProject_NotDetectedForHostingIntegrationOnly( + string packageReference, + CancellationToken cancellationToken + ) + { + using var h = await ProjectHarness.CreateAsync( + "Acme.AppHost", + extraItems: packageReference, + cancellationToken: cancellationToken + ); + + await Assert.That(await h.GetPropertyAsync("IsAspireHostProject", cancellationToken)).IsEqualTo("false"); + } + + [Test] + public async Task AspireHostProject_NotDetectedWhenAppHostPackageReferenceIsCommentedOut( + CancellationToken cancellationToken + ) + { + using var h = await ProjectHarness.CreateAsync( + "Acme.AppHost", + extraItems: """""", + cancellationToken: cancellationToken + ); + + await Assert.That(await h.GetPropertyAsync("IsAspireHostProject", cancellationToken)).IsEqualTo("false"); + } + + [Test] + public async Task AspireHostProject_ExplicitOptInBeforeSdkImportGetsHostDefaults( + CancellationToken cancellationToken + ) + { + using var h = await ProjectHarness.CreateAsync( + "Acme.AppHost", + preImportProps: "true", + cancellationToken: cancellationToken + ); + var props = await h.GetPropertiesAsync(cancellationToken, "IsAspireHostProject", "OutputType"); + + await Assert.That(props["IsAspireHostProject"]).IsEqualTo("true"); + await Assert.That(props["OutputType"]).IsEqualTo("Exe"); + } + [Test] public async Task RegularProject_IsNotAspireHostProject(CancellationToken cancellationToken) { diff --git a/templates/global.json b/templates/global.json index 09220e8..af27c88 100644 --- a/templates/global.json +++ b/templates/global.json @@ -3,6 +3,6 @@ "runner": "Microsoft.Testing.Platform" }, "msbuild-sdks": { - "Purview.BuildSdk": "2.2.0" + "Purview.BuildSdk": "2.2.1" } }