Include restored packages in aspire cache clear#15387
Conversation
The cache clear command was not clearing ~/.aspire/packages/ which contains restored NuGet packages for apphost server sessions. When the CLI binary is updated but the cached DLLs have the same version string, stale packages persist and cause failures (e.g. missing auth handshake in transport.ts). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15387Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15387" |
There was a problem hiding this comment.
Pull request overview
Updates the Aspire CLI so aspire cache clear also removes the restored NuGet package cache used by AppHost server sessions, preventing stale assemblies from persisting across CLI updates that share the same version string.
Changes:
- Add an optional
PackagesDirectorytoCliExecutionContextand wire it up inProgram.cs. - Extend
aspire cache clearto delete contents of~/.aspire/packages/in addition to existing cache/sdks/logs cleanup.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Aspire.Cli/Program.cs | Computes ~/.aspire/packages and passes it into CliExecutionContext. |
| src/Aspire.Cli/Commands/CacheCommand.cs | Adds deletion of restored packages directory during aspire cache clear. |
| src/Aspire.Cli/CliExecutionContext.cs | Introduces PackagesDirectory as an optional execution-context path. |
- Extract ClearDirectoryContents helper to deduplicate directory-clearing logic - Use EnumerateFiles with IgnoreInaccessible instead of GetFiles to handle inaccessible paths gracefully during enumeration - Add tests for packages directory clearing, skip predicate, null/nonexistent directory handling Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| return new DirectoryInfo(cacheDirectoryPath); | ||
| } | ||
|
|
||
| private static DirectoryInfo GetPackagesDirectory() |
There was a problem hiding this comment.
NIT: We could make this internal and use it inside BundleNuGetService.GetCacheDirectory to avoid duplication.
joperezr
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks a bunch for the quick fix David
|
Closing and reopening to ensure we get a clean run of CI now that transient issues have been fixed. |
|
🎬 CLI E2E Test Recordings — 53 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #23313095804 |
aspire cache clearwas not clearing~/.aspire/packages/which contains restored NuGet packages used by apphost server sessions. When the CLI binary is updated but the cached DLLs share the same version string (e.g. both13.2.0), stale packages persist and cause runtime failures.For example, after the RPC auth handshake was added in #15344, the CLI enforced authentication but the cached
Aspire.Hosting.CodeGeneration.TypeScript.dllstill contained the oldtransport.tswithout auth code — causing"Client must authenticate before invoking AppHost RPC methods"errors for TypeScript apphosts.Changes
PackagesDirectory(~/.aspire/packages/) toCliExecutionContextas an optional parameter (avoids churn on existing call sites)aspire cache clearnow also wipes~/.aspire/packages/alongside cache, sdks, and logsClearDirectoryContentshelper to deduplicate the repeated directory-clearing patternEnumerateFileswithIgnoreInaccessibleinstead ofGetFilesfor resilient enumeration