Repository navigation
Warn on unsupported AspireCliInvocationMode values - #21545
Conversation
Unsupported values were silently treated as Path. Emit ASPIRE014 from _ResolveAspireCliInvocation so misspelled modes such as DnxPinnedd are visible. Fixes #19714 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21545Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21545" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the invocation-mode warning and fallback changes.
No open issues 🎉
What changed in this PR
Addresses #19714 by warning about unsupported AspireCliInvocationMode values in AppHost CLI resolution while preserving the existing Path fallback behavior.
Changes:
- Adds suppressible warning
ASPIRE014for values other thanPath,Dnx, orDnxPinned, ignoring case. - Adds tests for invalid values, supported values, fallback resolution, and warning suppression.
- Documents the new diagnostic and fallback behavior.
| File | Description |
|---|---|
| tests/Aspire.Hosting.Sdk.Tests/AppHostSdkTargetsTests.cs | Adds validation, fallback, and suppression tests. |
| src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets | Emits ASPIRE014 for unsupported invocation modes. |
| docs/list-of-diagnostics.md | Documents ASPIRE014 and the default Path fallback. |
Review effort: Balanced
|
CI note: 🤖 Posted by AspireAgent (AI Agent) |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Merged
Local tests: 🤖 Posted by AspireAgent (AI Agent) |
Tests selector45 / 101 PR test projects · 3 PR jobs, from 2 changed files. Selected PR test projects (45 / 101)
Selected PR jobs (3)
How these were chosen — grouped by what changed
🔧 show 43
📦 affected project 🧪 Job reasons
Selection computed for commit |
Ankit Jain (radical)
left a comment
There was a problem hiding this comment.
No confirmed issues found in review.
|
Pull request created: #2085
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#2085 targeting Documents new ASPIRE014 warning. Triggered signal Note This draft PR needs human review before merging. |
## Description `AspireCliInvocationMode` only recognized `Dnx` and `DnxPinned`; every other value (for example `DnxPinnedd` or `DefinitelyInvalid`) silently fell through to `Path` resolution, so typos never surfaced. **Root cause:** `_ResolveAspireCliInvocation` passed the raw value to `ResolveAspireCliInvocation`, which treats anything other than `Dnx`/`DnxPinned` as `Path`. The only validation target (`_ValidateAspireCliDnxInvocationMode`) is conditioned on a DNX mode, so it was skipped for unrecognized values. **Fix:** `_ResolveAspireCliInvocation` emits a new suppressible `ASPIRE014` warning when the value is not `Path`, `Dnx` or `DnxPinned` (case-insensitive), and resolution continues in `Path` mode as before. I chose a warning instead of an error so that existing builds keep working while the mistake becomes visible. `ASPIRE013` is skipped because open PRs #21288 and #19880 both propose it. `docs/list-of-diagnostics.md` documents `ASPIRE014`. Fixes #19714 ### Before (main) Playground `DotnetProject.AppHost` with `-p:AspireUseCliBundle=true -p:AspireCliInvocationMode=DefinitelyInvalid -t:_ResolveAspireCliInvocation -v:diag`: ```text Task Parameter:AspireCliInvocationMode=DefinitelyInvalid Aspire CLI invocation selection: Dnx (aspire: , dnx: /root/aspire/.dotnet/dnx) <- Path-mode fallback (no aspire on PATH) 0 Error(s) 0 Warning(s) ``` A full `dotnet build` of the AppHost with the same value also reported `0 Warning(s)`. ### After ```text Aspire.Hosting.AppHost.in.targets(221,5): warning ASPIRE014: DotnetProject.AppHost is configured with AspireCliInvocationMode=DefinitelyInvalid, which is not a supported value. Supported values are Path, Dnx, and DnxPinned. The default Path invocation mode will be used. Aspire CLI invocation selection: Dnx (aspire: , dnx: /root/aspire/.dotnet/dnx) 0 Error(s) 1 Warning(s) ``` Valid values (`Path`, `DnxPinned`) still resolve to `Aspire` and `Dnx` without a warning. ### End-to-end with Aspire I ran `dotnet run` on `playground/DotnetProject/DotnetProject.AppHost` with `AspireCliInvocationMode=DefinitelyInvalid` and the Aspire CLI built from this branch (`17.0.0-dev`) on `PATH`. The warning appears during the build, and the AppHost then launches through `aspire run` (Path mode): ```text Building... ...Aspire.Hosting.AppHost.in.targets(221,5): warning ASPIRE014: DotnetProject.AppHost is configured with AspireCliInvocationMode=DefinitelyInvalid, which is not a supported value. Supported values are Path, Dnx, and DnxPinned. The default Path invocation mode will be used. Connecting to AppHost... Starting dashboard... AppHost: DotnetProject.AppHost.csproj Press CTRL+C to stop the AppHost and exit. ``` (The dashboard was skipped locally with `SkipDashboardProjectReference=true`.) ### Tests New tests in `tests/Aspire.Hosting.Sdk.Tests/AppHostSdkTargetsTests.cs`: - `ComputeRunArgumentsWarnsAndUsesPathModeWhenInvocationModeIsUnsupported` (`DefinitelyInvalid`, `DnxPinnedd`): asserts that `ASPIRE014` is emitted and that the fake `aspire` from `PATH` is selected. - `ComputeRunArgumentsDoesNotWarnWhenInvocationModeIsSupported` (unset, `Path`, `pAtH`, `Dnx`, `DnxPinned`). - `UnsupportedInvocationModeWarningCanBeSuppressed` (`NoWarn=ASPIRE014`). Without the fix, the two unsupported-value cases fail (`total: 8, failed: 2`). With the fix, the full `Aspire.Hosting.Sdk.Tests` project passes: 98 total, 94 passed, 0 failed, 4 skipped (Windows-only). ### Playground No playground file changed. In-repo playground AppHosts don't import `Aspire.Hosting.AppHost.props`, so `AspireUseCliBundle` isn't enabled by default and the packaged tasks assembly isn't present. Setting `AspireCliInvocationMode` in a playground project would therefore have no effect in a normal repo build. The playground proof above runs the existing `DotnetProject.AppHost` and passes those properties on the command line. ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - [x] No **🤖 Posted by AspireAgent (AI Agent)** Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 7b48978)
## Description `AspireCliInvocationMode` only recognized `Dnx` and `DnxPinned`; every other value (for example `DnxPinnedd` or `DefinitelyInvalid`) silently fell through to `Path` resolution, so typos never surfaced. **Root cause:** `_ResolveAspireCliInvocation` passed the raw value to `ResolveAspireCliInvocation`, which treats anything other than `Dnx`/`DnxPinned` as `Path`. The only validation target (`_ValidateAspireCliDnxInvocationMode`) is conditioned on a DNX mode, so it was skipped for unrecognized values. **Fix:** `_ResolveAspireCliInvocation` emits a new suppressible `ASPIRE014` warning when the value is not `Path`, `Dnx` or `DnxPinned` (case-insensitive), and resolution continues in `Path` mode as before. I chose a warning instead of an error so that existing builds keep working while the mistake becomes visible. `ASPIRE013` is skipped because open PRs #21288 and #19880 both propose it. `docs/list-of-diagnostics.md` documents `ASPIRE014`. Fixes #19714 ### Before (main) Playground `DotnetProject.AppHost` with `-p:AspireUseCliBundle=true -p:AspireCliInvocationMode=DefinitelyInvalid -t:_ResolveAspireCliInvocation -v:diag`: ```text Task Parameter:AspireCliInvocationMode=DefinitelyInvalid Aspire CLI invocation selection: Dnx (aspire: , dnx: /root/aspire/.dotnet/dnx) <- Path-mode fallback (no aspire on PATH) 0 Error(s) 0 Warning(s) ``` A full `dotnet build` of the AppHost with the same value also reported `0 Warning(s)`. ### After ```text Aspire.Hosting.AppHost.in.targets(221,5): warning ASPIRE014: DotnetProject.AppHost is configured with AspireCliInvocationMode=DefinitelyInvalid, which is not a supported value. Supported values are Path, Dnx, and DnxPinned. The default Path invocation mode will be used. Aspire CLI invocation selection: Dnx (aspire: , dnx: /root/aspire/.dotnet/dnx) 0 Error(s) 1 Warning(s) ``` Valid values (`Path`, `DnxPinned`) still resolve to `Aspire` and `Dnx` without a warning. ### End-to-end with Aspire I ran `dotnet run` on `playground/DotnetProject/DotnetProject.AppHost` with `AspireCliInvocationMode=DefinitelyInvalid` and the Aspire CLI built from this branch (`17.0.0-dev`) on `PATH`. The warning appears during the build, and the AppHost then launches through `aspire run` (Path mode): ```text Building... ...Aspire.Hosting.AppHost.in.targets(221,5): warning ASPIRE014: DotnetProject.AppHost is configured with AspireCliInvocationMode=DefinitelyInvalid, which is not a supported value. Supported values are Path, Dnx, and DnxPinned. The default Path invocation mode will be used. Connecting to AppHost... Starting dashboard... AppHost: DotnetProject.AppHost.csproj Press CTRL+C to stop the AppHost and exit. ``` (The dashboard was skipped locally with `SkipDashboardProjectReference=true`.) ### Tests New tests in `tests/Aspire.Hosting.Sdk.Tests/AppHostSdkTargetsTests.cs`: - `ComputeRunArgumentsWarnsAndUsesPathModeWhenInvocationModeIsUnsupported` (`DefinitelyInvalid`, `DnxPinnedd`): asserts that `ASPIRE014` is emitted and that the fake `aspire` from `PATH` is selected. - `ComputeRunArgumentsDoesNotWarnWhenInvocationModeIsSupported` (unset, `Path`, `pAtH`, `Dnx`, `DnxPinned`). - `UnsupportedInvocationModeWarningCanBeSuppressed` (`NoWarn=ASPIRE014`). Without the fix, the two unsupported-value cases fail (`total: 8, failed: 2`). With the fix, the full `Aspire.Hosting.Sdk.Tests` project passes: 98 total, 94 passed, 0 failed, 4 skipped (Windows-only). ### Playground No playground file changed. In-repo playground AppHosts don't import `Aspire.Hosting.AppHost.props`, so `AspireUseCliBundle` isn't enabled by default and the packaged tasks assembly isn't present. Setting `AspireCliInvocationMode` in a playground project would therefore have no effect in a normal repo build. The playground proof above runs the existing `DotnetProject.AppHost` and passes those properties on the command line. ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - [x] No **🤖 Posted by AspireAgent (AI Agent)** Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 7b48978)
## Description An explicit `AspireCliPath` takes precedence over `AspireCliInvocationMode`. That precedence is intentional and covered by `ComputeRunArgumentsUsesConfiguredAspireCliPathWhenDnxModeIsConfigured`. But `AspireCliPath` is often inherited from the environment; for example, the Aspire VS Code extension sets it for its terminals. In that case, a project that explicitly sets `AspireCliInvocationMode=Dnx`/`DnxPinned` silently runs the installed CLI instead, with nothing in the build output to say why. This takes option 2 from the issue. `_ResolveAspireCliInvocation` now emits a suppressible **`ASPIRE015`** warning when `AspireCliPath` overrides an explicit `Dnx`/`DnxPinned` mode. The warning names the path and tells the user how to opt into DNX (an empty `<AspireCliPath></AspireCliPath>` in the AppHost project) or how to silence it. Precedence is unchanged. `docs/list-of-diagnostics.md` documents the new diagnostic. Fixes #19713 > **Diagnostic ID:** renumbered from `ASPIRE013` to `ASPIRE015`. #21288 (merged) uses `ASPIRE013` for the required C# CLI-bundle error, and #21545 proposes `ASPIRE014`. The branch now merges `main` to pick up #21288. The output samples below show the warning under its new ID. ### Root cause `ResolveAspireCliInvocation.Execute` returns `Aspire` mode as soon as `AspireCliPath` is non-empty, before it looks at `AspireCliInvocationMode`. The targets only logged the selection at `Importance="Low"`, which is visible only in diagnostic verbosity (as the issue's `/v:diag` repro shows). ### Before / after **Unit tests** (`Aspire.Hosting.Sdk.Tests`, real `dotnet msbuild -t:ComputeRunArguments` against a generated AppHost with `AspireCliPath` in the environment): - `ComputeRunArgumentsWarnsWhenAmbientAspireCliPathOverridesDnxMode` (`Dnx`, `DnxPinned`, `dNxPiNnEd`): **3/3 fail before** (no `ASPIRE015` in output), **pass after**. They also assert that the resolved mode is still `Aspire` and that `RunCommand` is still the configured path. - `ComputeRunArgumentsDoesNotWarnWhenAspireCliPathDoesNotOverrideDnxMode` (`Path` mode; `DnxPinned` with `NoWarn=ASPIRE015`): passes before and after. - Full `Aspire.Hosting.Sdk.Tests` locally after the renumber and merge with `main`: 103 passed, 0 failed (3 Windows-only skipped). - After review feedback (suppression now relies on MSBuild's built-in `NoWarn` handling instead of an explicit check in the warning condition; `_AspireUseDnxCliRunHook` renamed to `_AspireCliInvocationModeRequestsDnx`): the `NoWarn=ASPIRE015` case still passes, and the full `Aspire.Hosting.Sdk.Tests` run passes locally (119 passed, 0 failed, 4 platform-specific skips). **E2E with a real AppHost and the Aspire CLI** (Linux, `playground/CustomResources/CustomResources.AppHost` temporarily set to `<AspireCliInvocationMode>DnxPinned</AspireCliInvocationMode>`, with `AspireCliPath=<aspire.cli 13.6.4>` in the environment, as the VS Code extension sets it, then `dotnet run`): Before (main): the CLI from `AspireCliPath` runs the AppHost, with no diagnostic: ``` Using launch settings from .../CustomResources.AppHost/Properties/launchSettings.json... ... Dashboard: https://CustomResources.dev.localhost:16159/login?t=... ``` After: same launch (precedence unchanged), and the override is now visible: ``` Using launch settings from .../CustomResources.AppHost/Properties/launchSettings.json... .../Aspire.Hosting.AppHost.in.targets(241,5): warning ASPIRE015: CustomResources.AppHost: AspireCliInvocationMode=DnxPinned is ignored because AspireCliPath is set to '/tmp/aspirecli/aspire'. AspireCliPath takes precedence over AspireCliInvocationMode and may be inherited from the environment, for example from the Aspire VS Code extension. To use DNX, clear it in the AppHost project with an empty <AspireCliPath></AspireCliPath> property. To keep using AspireCliPath, remove AspireCliInvocationMode or add ASPIRE015 to NoWarn. ... Dashboard: https://CustomResources.dev.localhost:16159/login?t=... ``` Following the warning's advice (adding `<AspireCliPath></AspireCliPath>` to the playground project, with the environment variable still set) resolves `_AspireResolvedCliInvocationMode=Dnx` and emits no `ASPIRE015`. The playground change was local proof only and is not committed: pinning the in-repo playground to `DnxPinned` would make it request an unpublished `aspire.cli` dev version. ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - [x] No **🤖 Posted by AspireAgent (AI Agent)** --------- Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ASPIRE014 is a warning, so list it under Warnings next to ASPIRE012. The warning ships in Aspire 17.1 (microsoft/aspire#21545; the 17.0 backport #22015 was closed), so qualify the SDK bullet and match the page's quoted message to the targets text. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Description
AspireCliInvocationModeonly recognizedDnxandDnxPinned; every other value (for exampleDnxPinneddorDefinitelyInvalid) silently fell through toPathresolution, so typos never surfaced.Root cause:
_ResolveAspireCliInvocationpassed the raw value toResolveAspireCliInvocation, which treats anything other thanDnx/DnxPinnedasPath. The only validation target (_ValidateAspireCliDnxInvocationMode) is conditioned on a DNX mode, so it was skipped for unrecognized values.Fix:
_ResolveAspireCliInvocationemits a new suppressibleASPIRE014warning when the value is notPath,DnxorDnxPinned(case-insensitive), and resolution continues inPathmode as before. I chose a warning instead of an error so that existing builds keep working while the mistake becomes visible.ASPIRE013is skipped because open PRs #21288 and #19880 both propose it.docs/list-of-diagnostics.mddocumentsASPIRE014.Fixes #19714
Before (main)
Playground
DotnetProject.AppHostwith-p:AspireUseCliBundle=true -p:AspireCliInvocationMode=DefinitelyInvalid -t:_ResolveAspireCliInvocation -v:diag:A full
dotnet buildof the AppHost with the same value also reported0 Warning(s).After
Valid values (
Path,DnxPinned) still resolve toAspireandDnxwithout a warning.End-to-end with Aspire
I ran
dotnet runonplayground/DotnetProject/DotnetProject.AppHostwithAspireCliInvocationMode=DefinitelyInvalidand the Aspire CLI built from this branch (17.0.0-dev) onPATH. The warning appears during the build, and the AppHost then launches throughaspire run(Path mode):(The dashboard was skipped locally with
SkipDashboardProjectReference=true.)Tests
New tests in
tests/Aspire.Hosting.Sdk.Tests/AppHostSdkTargetsTests.cs:ComputeRunArgumentsWarnsAndUsesPathModeWhenInvocationModeIsUnsupported(DefinitelyInvalid,DnxPinnedd): asserts thatASPIRE014is emitted and that the fakeaspirefromPATHis selected.ComputeRunArgumentsDoesNotWarnWhenInvocationModeIsSupported(unset,Path,pAtH,Dnx,DnxPinned).UnsupportedInvocationModeWarningCanBeSuppressed(NoWarn=ASPIRE014).Without the fix, the two unsupported-value cases fail (
total: 8, failed: 2). With the fix, the fullAspire.Hosting.Sdk.Testsproject passes: 98 total, 94 passed, 0 failed, 4 skipped (Windows-only).Playground
No playground file changed. In-repo playground AppHosts don't import
Aspire.Hosting.AppHost.props, soAspireUseCliBundleisn't enabled by default and the packaged tasks assembly isn't present. SettingAspireCliInvocationModein a playground project would therefore have no effect in a normal repo build. The playground proof above runs the existingDotnetProject.AppHostand passes those properties on the command line.Checklist
🤖 Posted by AspireAgent (AI Agent)