Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotnet format cannot find MSBuild on SDK 7.0.101 #1785

Open
LorianColtof opened this issue Dec 14, 2022 · 21 comments
Open

Dotnet format cannot find MSBuild on SDK 7.0.101 #1785

LorianColtof opened this issue Dec 14, 2022 · 21 comments
Assignees

Comments

@LorianColtof
Copy link

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

@craigktreasure
Copy link

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

craigktreasure added a commit to craigktreasure/SlnUp that referenced this issue Dec 17, 2022
There's a bug on macOS causing `dotnet format` to fail. See dotnet/format#1785.
craigktreasure added a commit to craigktreasure/SlnUp that referenced this issue Dec 17, 2022
Consolidate .NET installations using a new syntax:
https://github.com/actions/setup-dotnet#usage.
Pinning to .NET SDK 7.0.100 due to a bug executing `dotnet format` on
macOS. See dotnet/format#1785.
craigktreasure added a commit to craigktreasure/Treasure.Utils that referenced this issue Dec 21, 2022
  - `dotnet format` is broken on macOS with .NET SDK 7.0.101 (see dotnet/format#1785). So, we're installing 7.0.100 in addition to the latest and patching the `global.json` file at build time on macOS to prevent rolling forward to the latest SDK version. This means we'll use the latest on Windows and Linux, but macOS will be pinned o 7.0.100 for now until it's fixed.
craigktreasure added a commit to craigktreasure/Treasure.Utils that referenced this issue Dec 21, 2022
- `dotnet format` is broken on macOS with .NET SDK 7.0.101 (see dotnet/format#1785). So, we're installing 7.0.100 in addition to the latest and patching the `global.json` file at build time on macOS to prevent rolling forward to the latest SDK version. This means we'll use the latest on Windows and Linux, but macOS will be pinned o 7.0.100 for now until it's fixed.
@o-mdr
Copy link

o-mdr commented Jan 7, 2023

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

@jnoordsij
Copy link

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

@doominator42
Copy link

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

@ezra-lieb
Copy link

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.

@craigktreasure
Copy link

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.

@badsyntax
Copy link
Contributor

badsyntax commented Feb 16, 2023

@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.

@craigktreasure
Copy link

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.

@badsyntax
Copy link
Contributor

badsyntax commented Feb 16, 2023

@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?

@ezra-lieb
Copy link

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

@doominator42
Copy link

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.

@jnoordsij
Copy link

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 dotnet/dotnet-docker#4434), so can't test behavior for that.

@jdelucaa
Copy link

Getting the same issue in alpine 7.0.103-alpine3.17

@RikkiGibson RikkiGibson self-assigned this Feb 24, 2023
@rachelanordgren
Copy link

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

@craigktreasure
Copy link

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.

@jnoordsij
Copy link

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

@jamesHargreaves12
Copy link

I believe this another symptom of this - microsoft/MSBuildLocator#210

@devatwork
Copy link

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

@vmandic
Copy link

vmandic commented May 17, 2023

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

@jnoordsij
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests