MsBuild Path for BuildTools is not recognized correctly
- Dominant language
- C#
- Stars
- 4.2k
- Forks
- 778
- Avg merge
- 1h 15m
- Merged PRs (30d)
- 19
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched [issues](https://github.com/cake-build/cake/issues) to ensure it has not already been reported
### Cake runner
Cake .NET Tool
### Cake version
3.1
### Operating system
Windows
### Operating system architecture
X64
### CI Server
TeamCity / Azure DevOps Server (On Prem)
### What are you seeing?
Running the Cake Alias "MsBuild" on a machine where only BuildTools are installed can fail
```code
`MSBuild: Could not locate executable.
at Cake.Core.Tooling.Tool`1.RunProcess(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 164
at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action`1 postAction) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 81
at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 60
at Cake.Common.Tools.MSBuild.MSBuildRunner.Run(FilePath solution, MSBuildSettings settings) in C:\projects\cake\src\Cake.Common\Tools\MSBuild\MSBuildRunner.cs:line 48
at Cake.Common.Tools.MSBuild.MSBuildAliases.MSBuild(ICakeContext context, FilePath solution, MSBuildSettings settings) in C:\projects\cake\src\Cake.Common\Tools\MSBuild\MSBuildAliases.cs:line 102
at Submission#0.MSBuild(FilePath solution, MSBuildSettings settings)
```
In this PR https://github.com/cake-build/cake/pull/3795/files this was changed to "Program Files (x86)"
But it is also possible that the BuildTools are installed on "Program Files" Directory (image)

This is now the new behavior
https://learn.microsoft.com/en-us/visualstudio/msbuild/whats-new-msbuild-17-0?view=vs-2022
### What is expected?
Detection of the correct directory
### Steps to Reproduce
Windows Server 2022

### Output log
_No response_
Contributor guide
Research direction
Start with Cake.Common/Tools/MSBuild/MSBuildRunner.cs and the MSBuild-related path handling referenced by the stack trace. Reproduce on Windows with only BuildTools installed in either Program Files location, then verify that the MsBuild alias detects the correct directory instead of reporting that the executable cannot be located.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100