Skip to content

[release/10.0.1xx] Fix dotnet tool exec / dnx failing when tool exists in dotnet-tools.json but not yet restored - #53658

Merged
baronfel merged 3 commits into
release/10.0.1xxfrom
backport/pr-53361-to-release/10.0.1xx
May 13, 2026
Merged

baronfel merged 3 commits into
release/10.0.1xxfrom
backport/pr-53361-to-release/10.0.1xx

Conversation

@github-actions

@github-actions github-actions Bot commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #53361 to release/10.0.1xx

/cc @baronfel @Copilot

Tactics

Summary

dotnet tool exec and dnx fail with "Run 'dotnet tool restore' to make the command available" when a tool is listed in a local dotnet-tools.json manifest but dotnet tool restore has not yet been run. The root cause is in ToolExecuteCommand.Execute(): after calling ToolPackageRestorer.InstallPackage() to download the package, the resulting SaveToCache tuple was never passed to localToolsResolverCache.Save(). The subsequent LocalToolsCommandResolver thus found an empty cache and reported the tool as unavailable. The fix adds the missing localToolsResolverCache.Save() call immediately after a successful restore. This is a minimal, surgical change appropriate for a servicing release — it only touches the first-download code path and is guarded by a null check that preserves existing behavior for already-restored tools.

Customer Impact

Any user of dotnet tool exec <toolId> or dnx <toolId> in a directory where a dotnet-tools.json manifest references that tool (but dotnet tool restore has not been run) will receive the confusing error: "Run 'dotnet tool restore' to make the 'X' command available." This directly contradicts the design intent of dotnet tool exec/dnx, which are supposed to download and run tools on demand without prior setup. The issue was reproduced on SDK 10.0.103 (Linux x64) and affects all platforms. It is particularly impactful in CI/scripting scenarios. The only known workaround is to delete or rename the local dotnet-tools.json before running the command.

Regression?

Unknown — the issue was first reported against SDK 10.0.103. The original fix PR (#53361) does not identify a specific commit or earlier PR that introduced the regression. It may be a long-standing omission in the dotnet tool exec implementation rather than a recent regression.

Testing

  • Regression test added: ToolExecSucceedsWhenToolIsInLocalManifestButNotRestored in test/Microsoft.DotNet.PackageInstall.Tests/EndToEndToolTests.cs covers both the exec and dnx command variants. The test creates a dotnet-tools.json manifest referencing the tool, then runs the command without a prior dotnet tool restore, asserting that the command passes and produces expected output (Hello Tool!).
  • CI ran on the original PR Fix dotnet tool exec / dnx failing when tool exists in dotnet-tools.json but not yet restored #53361 (merged to main); this PR is a direct backport with no additional changes.
  • No additional manual repro steps are documented in the backport PR comments.

Risk

Low. The code change is 8 lines in a single method (ToolExecuteCommand.Execute()). The SaveToCache null check ensures the new code only runs on first download (when the tool is not yet in the on-disk cache); the existing behavior for already-restored tools is completely unchanged. A dedicated end-to-end regression test covers the fixed scenario for both exec and dnx. The change is isolated to the local-tool execution path and does not affect global tool installation or other SDK commands.

@github-actions github-actions Bot added the backport PR that has been backported to a servicing branch label Apr 1, 2026
@marcpopMSFT

Copy link
Copy Markdown
Member

/tactics

@baronfel

Copy link
Copy Markdown
Member

Approved over mail.

@baronfel
baronfel enabled auto-merge (squash) May 13, 2026 17:32
@baronfel
baronfel merged commit 9370159 into release/10.0.1xx May 13, 2026
30 of 31 checks passed
@baronfel
baronfel deleted the backport/pr-53361-to-release/10.0.1xx branch May 13, 2026 17:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport PR that has been backported to a servicing branch Servicing-approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants