microsoft / microsoft/aspire

AspireCliInvocationMode=DnxPinned is overridden by ambient AspireCliPath environment variable in VS Code

Open
#19,713 1 comment 1 reaction 0 assignees View on GitHub
area-cli area-vscode triage:bot-seen
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Description

When an AppHost is configured with `AspireUseCliBundle=true` and `AspireCliInvocationMode=DnxPinned`, the AppHost SDK still resolves the installed Aspire CLI when an `AspireCliPath` environment variable is present.

This is surprising because `DnxPinned` appears to request the paired `aspire.cli` package through `dnx`, but the explicit `AspireCliPath` value takes precedence and changes the selected invocation mode back to `Aspire`.

The `AspireCliPath` environment variable appears likely to be set by the Aspire VS Code extension, so this can happen without the project intentionally opting into an explicit CLI path.

### Reproduction

In a generic AppHost project using `Aspire.AppHost.Sdk/13.5.1`, set the following in `Directory.Build.props`:

```xml


true
DnxPinned

```

Ensure the shell/environment has an `AspireCliPath` value, for example:

```powershell
$env:AspireCliPath = "$HOME\.aspire\bin\aspire.exe"
```

Then run the SDK resolution target:

```powershell
dotnet msbuild app/Sample.AppHost/Sample.AppHost.csproj `
/t:_ResolveAspireCliInvocation `
/v:diag `
/p:AspireUseCliBundle=true `
/p:AspireCliInvocationMode=DnxPinned `
/nologo |
Select-String -Pattern 'AspireCliInvocationMode=|AspireCliPath=|Aspire CLI invocation selection:'
```

Observed result:

```text
Task Parameter:AspireCliInvocationMode=DnxPinned
Task Parameter:AspireCliPath=C:\Users\\.aspire\bin\aspire.exe
Aspire CLI invocation selection: Aspire (aspire: C:\Users\\.aspire\bin\aspire.exe, dnx: )
```

If `AspireCliPath` is cleared explicitly, the same property resolves through DNX as expected:

```powershell
dotnet msbuild app/Sample.AppHost/Sample.AppHost.csproj `
/t:_ResolveAspireCliInvocation `
/v:diag `
/p:AspireUseCliBundle=true `
/p:AspireCliInvocationMode=DnxPinned `
/p:AspireCliPath= `
/nologo |
Select-String -Pattern 'AspireCliInvocationMode=|AspireCliPath=|Aspire CLI invocation selection:'
```

Observed result with `AspireCliPath` cleared:

```text
Task Parameter:AspireCliInvocationMode=DnxPinned
Aspire CLI invocation selection: Dnx (aspire: , dnx: C:\Program Files\dotnet\dnx.cmd)
```

### Expected behavior

Either:

1. `AspireCliInvocationMode=DnxPinned` should take precedence over an ambient `AspireCliPath` environment variable when the project explicitly requests DNX-pinned invocation, or
2. the SDK/extension should make this precedence clear, and ideally warn when `AspireCliPath` overrides `AspireCliInvocationMode=DnxPinned`.

### Actual behavior

An ambient `AspireCliPath` causes the SDK to select `Aspire` invocation mode even when the project sets `AspireCliInvocationMode=DnxPinned`.

This makes it look as if `AspireCliInvocationMode` is not working, especially when the environment variable was injected by tooling rather than set by the user/project.

### Environment

- OS: Windows
- .NET SDK: 10.0.303
- AppHost SDK: `Aspire.AppHost.Sdk/13.5.1`
- Aspire CLI path observed: `%USERPROFILE%\.aspire\bin\aspire.exe`
- VS Code Aspire extension installed/running; likely source of the ambient `AspireCliPath` environment variable

Contributor guide

Open the contributing guide

Research direction

Start at the _ResolveAspireCliInvocation MSBuild target and trace how AspireCliInvocationMode and AspireCliPath are selected. Run the provided diagnostic msbuild command with DnxPinned and an ambient AspireCliPath; done means the explicit DnxPinned setting selects DNX, or the override is clearly warned about.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system, cli, developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.