Skip to content

aspire add --source rejects file-based AppHosts; works on .csproj #17304

@radical

Description

@radical

Summary

aspire add <pkg> --source <feed> fails on a file-based AppHost
(apphost.cs, as produced by aspire new aspire-empty) with:

❌ Cannot specify option '--source' when operating on a file-based app.
❌ The package installation failed with exit code 5.

The same command on a .csproj AppHost (produced by
aspire new aspire-starter) succeeds. So the user can override the
package feed for a .csproj AppHost but not for a file-based one,
with no in-CLI way to add a package from an arbitrary feed into a
file-based AppHost without hand-editing nuget.config first.

The error string comes from the .NET SDK's
dotnet package add --file … command. Not introduced by any
in-flight PR — the affected code path is unchanged on origin/main
(61d7844655). The dogfood install pattern (aspire new aspire-empty --source <hive> followed by aspire add … --source <hive>) is just the natural way for a user to hit it.

Repro

# Any current CLI; PR #17105's dogfood build (13.4.0-pr.17105.g8b0f3a08)
# was used to reproduce this.
CLI=/path/to/aspire
HIVE=/path/to/hives/<channel>/packages
VER=13.4.0-pr.NNNNN.gXXXXXXXX

# --- A. file-based AppHost: FAILS ---
"$CLI" new aspire-empty \
  --name FileBased --output /tmp/fb-test/FileBased \
  --source "$HIVE" --version "$VER" \
  --localhost-tld false --suppress-agent-init --non-interactive --nologo

"$CLI" add redis \
  --apphost /tmp/fb-test/FileBased/apphost.cs \
  --source "$HIVE" --version "$VER" \
  --non-interactive --nologo
echo "exit=$?"

# --- B. .csproj AppHost: SUCCEEDS ---
"$CLI" new aspire-starter \
  --name CsProjBased --output /tmp/cs-test/CsProjBased \
  --source "$HIVE" --version "$VER" \
  --test-framework None --use-redis-cache false \
  --localhost-tld false --suppress-agent-init --non-interactive --nologo

"$CLI" add redis \
  --apphost /tmp/cs-test/CsProjBased/CsProjBased.AppHost/CsProjBased.AppHost.csproj \
  --source "$HIVE" --version "$VER" \
  --non-interactive --nologo
echo "exit=$?"

Expected

aspire add <pkg> --source <feed> should either:

  1. work the same way on file-based AppHosts as on .csproj
    AppHosts (--source override resolves the package from that feed
    and writes the corresponding #:package <name>@<ver> directive
    into apphost.cs), or
  2. fail fast in Aspire CLI itself — before delegating to
    dotnet package add — with a message that names --source,
    names the file-based AppHost, and tells the user how to achieve
    the same effect (e.g. register the feed in the project's
    nuget.config).

Either way, behavior must not silently diverge between the two
AppHost shapes.

Actual

File-based path:

Searching for Aspire integrations...
Adding Aspire hosting integration...
❌ Cannot specify option '--source' when operating on a file-based app.
❌ The package installation failed with exit code 5.

CLI exit code: 5 (correctly non-zero — the SDK error is surfaced).

.csproj path with the same arguments:

Searching for Aspire integrations...
Adding Aspire hosting integration...
✅ The package Aspire.Hosting.Redis::13.4.0-pr.17105.g8b0f3a08 was added successfully.

CLI exit code: 0. The AppHost csproj gains:

<PackageReference Include="Aspire.Hosting.Redis" Version="13.4.0-pr.17105.g8b0f3a08" />

Env

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions