format icon indicating copy to clipboard operation
format copied to clipboard

Dotnet format cannot find MSBuild on SDK 7.0.101

Open LorianColtof opened this issue 2 years ago • 21 comments

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

LorianColtof avatar Dec 14 '22 10:12 LorianColtof

I'm seeing the same, but only on macOS. My Ubuntu and Windows builds work fine with 7.0.101.

craigktreasure avatar Dec 17 '22 05:12 craigktreasure

Seeing the same problem on dotnet/sdk:7.0.101-alpine3.16. Is there a workaround?

o-mdr avatar Jan 07 '23 21:01 o-mdr

Still an issue on mcr.microsoft.com/dotnet/sdk:7.0.102-alpine3.17 with dotnet format version 7.0.357101+49c2ef651359526841d13e66129b71d1bcd9cef9

jnoordsij avatar Jan 11 '23 08:01 jnoordsij

I got this issue on mcr.microsoft.com/dotnet/sdk:7.0.102-alpine3.17 and 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:

/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.2/hostfxr.so
/usr/share/dotnet/sdk/7.0.102/DotnetTools/dotnet-format/hostfxr.so
/lib/hostfxr.so
/usr/local/lib/hostfxr.so
/usr/lib/hostfxr.so
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.2/libhostfxr.so
/usr/share/dotnet/sdk/7.0.102/DotnetTools/dotnet-format/libhostfxr.so
/lib/libhostfxr.so
/usr/local/lib/libhostfxr.so
/usr/lib/libhostfxr.so

On dotnet/sdk:6.0.405-alpine3.17 it is loaded directly from /usr/share/dotnet/host/fxr/6.0.13/libhostfxr.so without 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.

ln -s /usr/share/dotnet/host/fxr/7.0.2/libhostfxr.so /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.2/libhostfxr.so

doominator42 avatar Jan 19 '23 01:01 doominator42

Running this locally on MacOS with dotnet version

dotnet --version
7.0.102

And getting same issue

➜ dotnet format -v diag
  The dotnet runtime version is '7.0.2'.
  The dotnet CLI version is '7.0.102'.
Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer.

ezra-lieb avatar Feb 15 '23 23:02 ezra-lieb

Running this locally on MacOS with dotnet version

dotnet --version
7.0.102

And getting same issue

➜ dotnet format -v diag
  The dotnet runtime version is '7.0.2'.
  The dotnet CLI version is '7.0.102'.
Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer.

Have you tried 7.0.103? That seems to have fixed the issue for me.

craigktreasure avatar Feb 16 '23 01:02 craigktreasure

@craigktreasure i've just installed the latest version (macos/7.0.200/arm64) and i get the same error:

❯ dotnet format

Welcome to .NET 7.0!
---------------------
SDK Version: 7.0.200

Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer.

badsyntax avatar Feb 16 '23 06:02 badsyntax

I was unable to use 7.0.200 due to other issues. 7.0.103 was released at the same time and is still supported. Worth a try.

craigktreasure avatar Feb 16 '23 06:02 craigktreasure

@craigktreasure i've tried with 7.0.103 and 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?

badsyntax avatar Feb 16 '23 06:02 badsyntax

I updated my MacOS to Ventura 13.2.1 and dotnet format now works. Was previously on macOS Catalina so possible that isnt supported by dotnet 7

ezra-lieb avatar Feb 16 '23 22:02 ezra-lieb

It's still not working in Alpine images

[user@host ~]$ sudo docker run --rm -it --pull=always mcr.microsoft.com/dotnet/sdk:7.0-alpine3.17 ash
7.0-alpine3.17: Pulling from dotnet/sdk
Digest: sha256:bca0b230d1ddb32649a2f89f8ec1dc8ddce5a1ec497a17cbfd0009ae458ebc4e
Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:7.0-alpine3.17
/ # mkdir app
/ # cd app
/app # dotnet new console
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /app/app.csproj:
  Determining projects to restore...
  Restored /app/app.csproj (in 47 ms).
Restore succeeded.


/app # dotnet format
Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer.

Surprisingly, it works after installing dotnet7-sdk inside the container:

/app # apk add --update dotnet7-sdk
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.17/community/x86_64/APKINDEX.tar.gz
(1/13) Installing dotnet-host (7.0.2-r0)
(2/13) Installing dotnet7-hostfxr (7.0.2-r0)
(3/13) Installing lttng-ust (2.13.3-r0)
(4/13) Installing xz-libs (5.2.9-r0)
(5/13) Installing libunwind (1.6.2-r0)
(6/13) Installing dotnet7-runtime (7.0.2-r0)
(7/13) Installing aspnetcore7-runtime (7.0.2-r0)
(8/13) Installing aspnetcore7-targeting-pack (7.0.2-r0)
(9/13) Installing dotnet7-apphost-pack (7.0.2-r0)
(10/13) Installing dotnet7-targeting-pack (7.0.2-r0)
(11/13) Installing dotnet7-templates (7.0.102-r0)
(12/13) Installing netstandard21-targeting-pack (7.0.102-r0)
(13/13) Installing dotnet7-sdk (7.0.102-r0)
Executing busybox-1.35.0-r29.trigger
OK: 528 MiB in 47 packages
/app # dotnet format
/app #

The sdk provided by the image is located at /usr/share/dotnet while the package dotnet7-sdk installs at /usr/lib/dotnet, so maybe this has to do with how Alpine resolves libraries. I don't know much in that department.

Also, using LD_LIBRARY_PATH=/usr/share/dotnet/host/fxr/7.0.3 dotnet format works.

doominator42 avatar Feb 17 '23 00:02 doominator42

Still an issue on the 8.0-preview image as well:

> docker run --rm -it mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine3.17 sh -c "mkdir /tmp/test && cd /tmp/test && dotnet new console && dotnet format"
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 62 ms).
Restore succeeded.


Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer.

Note that 7.0.200 has no Docker image published yet (see https://github.com/dotnet/dotnet-docker/discussions/4434), so can't test behavior for that.

jnoordsij avatar Feb 22 '23 11:02 jnoordsij

Getting the same issue in alpine 7.0.103-alpine3.17

jdelucaa avatar Feb 24 '23 18:02 jdelucaa

Getting the same issue with multiple versions. Have tried newest release and downgrading 😞

rachelanordgren avatar Mar 06 '23 16:03 rachelanordgren

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-format tool 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.

craigktreasure avatar Mar 06 '23 19:03 craigktreasure

Still an issue on mcr.microsoft.com/dotnet/sdk:7.0.202-alpine3.17

jnoordsij avatar Mar 15 '23 10:03 jnoordsij

I believe this another symptom of this - https://github.com/microsoft/MSBuildLocator/issues/210

jamesHargreaves12 avatar Apr 20 '23 22:04 jamesHargreaves12

Still an issue on mcr.microsoft.com/dotnet/sdk:7.0.203-alpine3.17. I added the following line to my Dockerfile just before invoking the dotnet format command as a workaround:

RUN ln -s /usr/share/dotnet/host/fxr/7.0.5/libhostfxr.so /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.5/libhostfxr.so

devatwork avatar May 01 '23 12:05 devatwork

@devatwork thanks a million, this actually worked...

vmandic avatar May 17 '23 16:05 vmandic

This seems to be resolved in the latest stable Alpine image sdk version (mcr.microsoft.com/dotnet/sdk:7.0.305-alpine3.18 and also the .304 variant), however it is still present on the latest 8.0 preview version (mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine3.18).

jnoordsij avatar Jun 27 '23 09:06 jnoordsij

Working on the 7.0.30x and 7.0.40x line now, but still an issue on mcr.microsoft.com/dotnet/sdk:8.0-alpine3.18 (which is a rc version). I'm a bit confused by how the .NET codebase works and how this behaves so inconsistent, but I would hope it would somehow be possible to ensure this works before the 8.0 release drops...

jnoordsij avatar Sep 13 '23 09:09 jnoordsij