dotnet / dotnet/sdk

dotnet tool restore misattributes commands between packages when DOTNET_CLI_HOME is set to a fresh directory

Open
#53,783 6 comments 8 reactions 2 assignees Claimed by @marcpopMSFT View on GitHub
Area-Tools untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

`dotnet tool restore` misattributes commands between tools when `DOTNET_CLI_HOME` is set to a custom (fresh) directory. The second tool in the manifest is reported as containing the first tool's command name, causing a partial restore failure.

This only manifests when:

1. `DOTNET_CLI_HOME` points to a directory with no existing tool resolver cache
2. The tool manifest contains 2+ tools

With the default `DOTNET_CLI_HOME` (or on a second run when the cache is warm), the restore succeeds. This reproduces on **every SDK version tested**: 8.0.125, 8.0.419, 9.0.115, 9.0.312, 10.0.101, 10.0.201, and 10.0.300-preview.

Setting `DOTNET_CLI_HOME` to a custom path is common in CI/build systems to isolate the tool resolver cache per-build.

### To Reproduce

```bash
mkdir repro && cd repro && mkdir .config

cat > global.json << 'EOF'
{ "sdk": { "version": "10.0.201" } }
EOF

cat > .config/dotnet-tools.json << 'EOF'
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "9.0.4",
"commands": [ "dotnet-ef" ]
},
"dotnet-outdated-tool": {
"version": "4.6.8",
"commands": [ "dotnet-outdated" ]
}
}
}
EOF

# FAILS — fresh DOTNET_CLI_HOME
DOTNET_CLI_HOME=$(mktemp -d) dotnet tool restore

# WORKS — default DOTNET_CLI_HOME
dotnet tool restore

# WORKS — second run (warm cache)
DOTNET_CLI_HOME=$(mktemp -d) bash -c 'dotnet tool restore; dotnet tool restore'
```

**Expected:** Both tools restore successfully on the first run.

**Actual:**

```
Tool 'dotnet-ef' (version '9.0.4') was restored. Available commands: dotnet-ef
The command "dotnet-outdated" specified in the tool manifest file is not contained in the package
with Package Id dotnet-outdated-tool. The commands contained in the package are dotnet-ef.
Restore partially failed.
```

### Exceptions (if any)

No exception — `dotnet tool restore` exits with code 1 and the error message above.

### Further technical details

dotnet --info

```
.NET SDK:
Version: 10.0.300-preview.0.26177.108
Commit: cf1948f9c2
Workload version: 10.0.300-manifests.34a88a22
MSBuild version: 18.6.0-preview-26177-108+cf1948f9c

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64

.NET SDKs installed:
8.0.125, 8.0.419, 9.0.115, 9.0.312, 10.0.101, 10.0.201, 10.0.300-preview.0.26177.108
```

- Reproduced from CLI only (no IDE involved)
- Bug reproduces on **all** installed SDK versions (8.0.x through 10.0.x)
- **Workaround:** retry `dotnet tool restore` a second time — the warm cache succeeds

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.