format: Dotnet format cannot find MSBuild on SDK 7.0.101
It fails with the error message Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer..
Steps to reproduce:
> docker run --rm -it mcr.microsoft.com/dotnet/sdk:7.0.101-alpine3.17 sh
/ # mkdir /tmp/test
/ # cd /tmp/test
/tmp/test # dotnet new console
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring /tmp/test/test.csproj:
Determining projects to restore...
Restored /tmp/test/test.csproj (in 83 ms).
Restore succeeded.
/tmp/test # dotnet format
Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer.
Output of dotnet format --version:
7.0.352902+f7beff0efdb20b8f22516d310279204a3fa9ef50
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 8
- Comments: 21 (2 by maintainers)
Commits related to this issue
- Pin to 7.0.100 There's a bug on macOS causing `dotnet format` to fail. See https://github.com/dotnet/format/issues/1785. — committed to craigktreasure/SlnUp by craigktreasure 2 years ago
- Consolidate .NET SDK installation and pin to 7.0.100 (#159) Consolidate .NET installations using a new syntax: https://github.com/actions/setup-dotnet#usage. Pinning to .NET SDK 7.0.100 due to a bu... — committed to craigktreasure/SlnUp by craigktreasure 2 years ago
- Patch global.json to 7.0.100 for macOS - `dotnet format` is broken on macOS with .NET SDK 7.0.101 (see https://github.com/dotnet/format/issues/1785). So, we're installing 7.0.100 in addition to the... — committed to craigktreasure/Treasure.Utils by craigktreasure 2 years ago
- Patch global.json to 7.0.100 for macOS (#31) - `dotnet format` is broken on macOS with .NET SDK 7.0.101 (see https://github.com/dotnet/format/issues/1785). So, we're installing 7.0.100 in addition to... — committed to craigktreasure/Treasure.Utils by craigktreasure 2 years ago
@craigktreasure i’ve tried with
7.0.103and it results in the same problem 😦 it would be great to get some feedback from the dotnet devs, do we know they’re even aware of this issue?Still an issue on the 8.0-preview image as well:
Note that
7.0.200has no Docker image published yet (see https://github.com/dotnet/dotnet-docker/discussions/4434), so can’t test behavior for that.Running this locally on MacOS with dotnet version
And getting same issue
This seems to be resolved in the latest stable Alpine image sdk version (
mcr.microsoft.com/dotnet/sdk:7.0.305-alpine3.18and also the.304variant), however it is still present on the latest 8.0 preview version (mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine3.18).Still an issue on
mcr.microsoft.com/dotnet/sdk:7.0.203-alpine3.17. I added the following line to myDockerfilejust before invoking thedotnet formatcommand as a workaround:I’m not an expert, but it seems that the release/7.x branch is in working condition. I built and installed it locally and it works for me. However, there’s not a build for the latest from that branch in the .NET 7 NuGet feed (https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json). Feels like they need to spin a new build and for the SDK to pick it up. Not sure how often that happens.
To some extent, I kinda wish support would go back to the
dotnet-formattool so that it could rev in times like this. It’s valuable to those of us that use it, but it’s clearly not getting the attention it deserves despite it being integrated into the SDK. Quite unfortunate.Getting the same issue in alpine 7.0.103-alpine3.17
I got this issue on
mcr.microsoft.com/dotnet/sdk:7.0.102-alpine3.17and traced it.For some reason, MSBuildLocator does not find
libhostfxr.so(which is in /usr/share/dotnet/host/fxr/7.0.2/). From the trace, it tries to load it from the following paths:On
dotnet/sdk:6.0.405-alpine3.17it is loaded directly from/usr/share/dotnet/host/fxr/6.0.13/libhostfxr.sowithout even looking in other directories. Also,dotnet/sdk:7.0.102(debian) works fine, so it must be specific to alpine.Adding a symlink in the sdk directory works as a workaround until it is fixed.
Still an issue on
mcr.microsoft.com/dotnet/sdk:7.0.102-alpine3.17with dotnet format version7.0.357101+49c2ef651359526841d13e66129b71d1bcd9cef9