Sometimes got error "Unable to locate dotnet CLI. Ensure that it is on the PATH"
Description:
I found setup-dotnet is not always reliable.
For example, in same GitHub Action build:
Attempt #1failed: https://github.com/hongbo-miao/hongbomiao.com/actions/runs/12211957209/attempts/1Attempt #2succeed: https://github.com/hongbo-miao/hongbomiao.com/actions/runs/12211957209
Unable to locate dotnet CLI. Ensure that it is on the PATH.
Platform:
- [ ] Ubuntu
- [ ] macOS
- [x] Windows
Runner type:
- [x] Hosted
- [ ] Self-hosted
Repro steps:
steps:
- name: Checkout
uses: actions/[email protected]
- name: Set up NuGet
uses: nuget/[email protected]
with:
nuget-version: 6.12.1
- name: Set up .NET Core
uses: actions/[email protected]
with:
global-json-file: hardware-in-the-loop/national-instruments/veristand/VeriStandZeroMQBridge/global.json
- name: Install dependencies
working-directory: hardware-in-the-loop/national-instruments/veristand/VeriStandZeroMQBridge
run: |
nuget restore VeriStandZeroMQBridge.sln
dotnet tool restore
- name: Lint C# (format)
working-directory: hardware-in-the-loop/national-instruments/veristand/VeriStandZeroMQBridge
run: |
dotnet format VeriStandZeroMQBridge.sln --verify-no-changes
- name: Lint C# (CSharpier)
working-directory: hardware-in-the-loop/national-instruments/veristand/VeriStandZeroMQBridge
run: |
dotnet csharpier --check .
hardware-in-the-loop/national-instruments/veristand/VeriStandZeroMQBridge/global.json
{
"sdk": {
"version": "8.0.404"
}
}
Expected behavior:
I expect dotnet CLI work all time if no code changes.
Actual behavior:
Even same code in same build, sometimes I got error "Unable to locate dotnet CLI. Ensure that it is on the PATH"
Also, for this pull request, when bumping csharpier from 0.30.2 to 0.30.3, no matter how many times I tried, I always got
Unable to locate dotnet CLI. Ensure that it is on the PATH
You can see dotnet CLI got installed at C:\Program Files\dotnet, but next step it says cannot find it
Unable to locate dotnet CLI. Ensure that it is on the PATH.
Hello @hongbo-miao, Thank you for creating this issue. We will investigate it and provide feedback as soon as we have some updates.
Just found more people having same issue. I posted a workaround solution which works for me at https://github.com/dotnet/sdk/issues/44957#issuecomment-2543349940 Also, I posted some info which may help you fix the issue. ☺️
Hello @hongbo-miao, Thank you for providing the workaround. This problem appears to be related to dotnet-format rather than setup-dotnet. The error "Unable to locate dotnet CLI. Ensure that it is on the PATH" is commonly associated with dotnet-format.
We have reviewed your comment and would like to clarify that the DOTNET_ROOT environment variable now points to D:\a_temp.dotnet instead of C:\Program Files\dotnet because the DOTNET_INSTALL_DIR environment variable is set to ${{ runner.temp }}/.dotnet. The setup-dotnet action sets DOTNET_ROOT to the same value as DOTNET_INSTALL_DIR. For reference, please visit code snippet here. The dotnet/sdk#44957 issue you referenced is relevant and might be worth following for any updates or potential fixes from the dotnet team.
Hello @hongbo-miao, please let us know if you have any concerns or need further clarification on the above to assist further :)
@aparnajyothi-y there is only has a workaround way, and still not fixed.
Hi @hongbo-miao, Thank you for the update. As previously mentioned, this issue originates from how dotnet-format resolves the CLI path, not from how actions/setup-dotnet installs the SDK. A proper resolution would need to come from the dotnet-format tool itself—ideally by honoring DOTNET_ROOT or supporting a configurable path.
We recommend tracking the upstream issue (dotnet/sdk#44957) for any updates. Since there’s no actionable change required in this action, we’ll go ahead and close this issue for now.
Please feel free to reach out if you have any questions or need further clarification—we’d be happy to reopen the issue if needed.
Hello @hongbo-miao, Since there’s no actionable change required in this action, we’ll go ahead and close this issue for now. Please feel free to reach out if you have any questions or need further clarification :)