Skip to content

Include restored packages in aspire cache clear#15387

Merged
joperezr merged 3 commits intorelease/13.2from
davidfowler/cache-clear-packages-restore
Mar 19, 2026
Merged

Include restored packages in aspire cache clear#15387
joperezr merged 3 commits intorelease/13.2from
davidfowler/cache-clear-packages-restore

Conversation

@davidfowl
Copy link
Contributor

@davidfowl davidfowl commented Mar 19, 2026

aspire cache clear was 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. both 13.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.dll still contained the old transport.ts without auth code — causing "Client must authenticate before invoking AppHost RPC methods" errors for TypeScript apphosts.

Changes

  • Add PackagesDirectory (~/.aspire/packages/) to CliExecutionContext as an optional parameter (avoids churn on existing call sites)
  • aspire cache clear now also wipes ~/.aspire/packages/ alongside cache, sdks, and logs
  • Extract ClearDirectoryContents helper to deduplicate the repeated directory-clearing pattern
  • Use EnumerateFiles with IgnoreInaccessible instead of GetFiles for resilient enumeration
  • Add unit tests for packages directory clearing, skip predicate, and edge cases

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>
Copilot AI review requested due to automatic review settings March 19, 2026 12:49
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15387

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15387"

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PackagesDirectory to CliExecutionContext and wire it up in Program.cs.
  • Extend aspire cache clear to 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.

davidfowl and others added 2 commits March 19, 2026 09:00
- 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>
@joperezr joperezr added the Servicing-approved Approved for servicing release label Mar 19, 2026
return new DirectoryInfo(cacheDirectoryPath);
}

private static DirectoryInfo GetPackagesDirectory()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: We could make this internal and use it inside BundleNuGetService.GetCacheDirectory to avoid duplication.

Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks a bunch for the quick fix David

@joperezr
Copy link
Member

Closing and reopening to ensure we get a clean run of CI now that transient issues have been fixed.

@joperezr joperezr closed this Mar 19, 2026
@joperezr joperezr reopened this Mar 19, 2026
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Mar 19, 2026
@github-actions
Copy link
Contributor

🎬 CLI E2E Test Recordings — 53 recordings uploaded (commit 5b002b1)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23313095804

@joperezr joperezr merged commit a79dde4 into release/13.2 Mar 19, 2026
755 of 763 checks passed
@joperezr joperezr deleted the davidfowler/cache-clear-packages-restore branch March 19, 2026 23:05
@dotnet-policy-service dotnet-policy-service bot modified the milestone: 13.2 Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants