dotnet format fails after installing new version of the .NET 8 SDK due to missing executable
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
**Summary**
The file
c:\Program Files\dotnet\sdk\8.0.4xx\DotnetTools\dotnet-format\BuildHost-net472\Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe
is missing from the .NET SDK 8.0.409 through 8.0.412 distributions.
This causes the dotnet format command to fail.
**Details**
We have a solution with ~90 projects and use dotnet format as part of our integration pipeline.
We have a global.json file in the root of our solution/working copy:
{
"sdk": {
"version": "8.0.400",
"allowPrerelease": false,
"rollForward": "patch"
}
}
We have a .bat script that checks source file formatting using the following line:
dotnet format "%RootDir%\All.sln" --verify-no-changes -v normal>>"%CheckSourceFileFormattingLog%"
This command has failed the last four times we updated .NET 8 SDK, i.e., 8.0.409, 8.0.410, 8.0.411, and now 8.0.412.
Exception:
Unhandled exception: System.Exception: The build host could not be found at 'C:\Program Files\dotnet\sdk\8.0.412\DotnetTools\dotnet-format\BuildHost-net472\Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe'
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.AssertBuildHostExists(String buildHostPath)
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.GetDotNetFrameworkBuildHostPath()
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.CreateDotNetFrameworkBuildHostStartInfo()
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.GetBuildHostAsync(BuildHostProcessKind buildHostKind, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.GetBuildHostWithFallbackAsync(BuildHostProcessKind buildHostKind, String projectOrSolutionFilePath, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectFileInfosAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectInfosFromPathAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadAsync(CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress`1 progress, ILogger msbuildLogger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress`1 progress, ILogger msbuildLogger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync(String solutionFilePath, ILogger msbuildLogger, IProgress`1 progress, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceLoader.LoadAsync(String solutionOrProjectPath, WorkspaceType workspaceType, String binaryLogPath, Boolean logWorkspaceWarnings, ILogger logger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.CodeFormatter.OpenMSBuildWorkspaceAsync(String solutionOrProjectPath, WorkspaceType workspaceType, Boolean noRestore, Boolean requiresSemantics, String binaryLogPath, Boolean logWorkspaceWarnings, ILogger logger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath)
at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.FormatAsync(FormatOptions formatOptions, ILogger`1 logger, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
This is on Windows 11, but the problem has also been observed on Windows Server 2016 and Windows Server 2019. On Windows Server 2016, the problem occurred recently because .NET SDK 8 was updated to 8.0.411 as part of a security update.
Visual Studio 17.14.8 and SSMS 21.4.8 installed.
.NET SDK 8.0.412 installed using the standalone installer.
The problem is that the Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe file is missing from the dotnet-format subfolder.
If you install .NET SDK 8.0.412 and look at the folders
c:\Program Files\dotnet\sdk\8.0.412\DotnetTools\dotnet-format\BuildHost-net472\
c:\Program Files\dotnet\sdk\8.0.412\DotnetTools\dotnet-watch\8.0.412-servicing.25320.8\tools\net8.0\any\BuildHost-net472\
you will find that Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe is missing from the former. All other files in those folders and their subfolders are identical. This is clearly a bug/omission in the distribution of .NET 8 SDK.
To fix this, you have to open a command prompt and run the following command:
copy /B "c:\Program Files\dotnet\sdk\8.0.412\DotnetTools\dotnet-watch\8.0.412-servicing.25320.8\tools\net8.0\any\BuildHost-net472\Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe" "c:\Program Files\dotnet\sdk\8.0.412\DotnetTools\dotnet-format\BuildHost-net472\Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe"
Running a similar (paths changing) command has now been necessary for 8.0.409 through 8.0.412.
Note: Changing our target to .NET 9 (including our global.json) file might have fixed the problem as the .NET SDK 9 distributions do not seem to suffer from this problem, but we are not planning on switching to a new version before .NET 10 has been released, i.e., skipping .NET 9.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.