dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.6k stars 1.04k forks source link

Wrong "workload not found" message #31835

Open rmarinho opened 1 year ago

rmarinho commented 1 year ago

Describe the bug

When trying to build a project without any workloads for .NET Multi-platform App UI (MAUI) , the build process fails with an error related to "maui-tizen" even though it is not required for the current project.

To Reproduce

repo: https://github.com/rmarinho/DotNetTestTizen

Exceptions (if any)

To build this project, the following workloads must be installed: maui-tizen
To install these workloads, run the following command: dotnet workload restore

binlog : test-2.binlog.zip

Expected Result: The build process should throw a error saying maui workload needs to be installed.

Further technical details


 Version:   7.0.202
 Commit:    6c74320bc3

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.6
 OS Platform: Darwin
 RID:         osx.12-x64
 Base Path:   /Users/runner/hostedtoolcache/dotnet/sdk/7.0.202/

Host:
  Version:      7.0.4
  Architecture: x64
  Commit:       0a396acafe

.NET SDKs installed:
  7.0.202 [/Users/runner/hostedtoolcache/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.4 [/Users/runner/hostedtoolcache/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.4 [/Users/runner/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/Users/runner/hostedtoolcache/dotnet]

global.json file:
  /Users/runner/work/1/s/global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
marcpopMSFT commented 1 year ago

From the binlog, there are two packs identified as missing: Microsoft.Maui.Sdk.net7 and Microsoft.Maui.Resizetizer.Sdk. Our logic here tries to map the pack onto the first workload it finds that requires these packs which happens to be maui-tizen. @jonathanpeppers can the workloads be reordered in the workload manifest so that a different one ends up being the one reported or should we try to have a more limited list of which we'd report (which would be a bit hacky)

jonathanpeppers commented 1 year ago

@marcpopMSFT I believe maui-tizen is listed somewhere in the middle:

https://github.com/dotnet/maui/blob/c7b7636310da0c5ce7785abeb31d97827cd131bb/src/Workload/Microsoft.NET.Sdk.Maui/WorkloadManifest.in.json#L16

If you have a suggestion like "put it first" or "put it last", @rmarinho should give it a try. You can edit the file locally at:

C:\Program Files\dotnet\sdk-manifests\7.0.100\microsoft.net.sdk.maui\WorkloadManifest.json
marcpopMSFT commented 1 year ago

@dsplaisted should we have more predictable code in the sdk or just rely on the order? @jonathanpeppers , I think putting it last should mean it's not the one listed if this particular issue is hit. I'd put them in the order you'd want them to be listed in the case of an error like this. Of course, I'm assuming that the order in the manifest impacts this.

dsplaisted commented 1 year ago

We try to suggest the "best" workload to install that will satisfy the packs that are needed to build the project. We define "best" as "requiring the fewest additional workload packs to be installed". So probably in this case installing the Tizen workload would result in installing fewer additional packs than the maui workload, and both would satisfy the requirements.

Or there could be a bug in the code. The code is here: https://github.com/dotnet/sdk/blob/main/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/WorkloadSuggestionFinder.cs

rmarinho commented 1 year ago

What i don't understand is that if i m not building for that workload, why would it throw?! if i just need Microsoft.Maui.Sdk.net7 and Microsoft.Maui.Resizetizer.Sdk for the other workloads that i specify on my csproj.

dsplaisted commented 1 year ago

The SDK doesn't know which workload you need, just which workload packs are missing. There can be multiple workloads that would supply those packs. In this case it looks like either the Tizen or Maui workloads would install the packs that are needed, but the Tizen workload would overall install fewer additional packs, so it suggests that one.

SilenceCZ commented 4 months ago

I have resolved the same tizen error after many hours thanks to this tidbit: "To use Visual Studio for Mac with .NET 8, enable the Visual Studio > Preferences > Other > Preview Features > Use the .NET 8 SDK if installed (requires restart) checkbox." To double check, once I turn this feature off again, maui-tizen missing workload error is back. Hope this helps somebody else as well!

avin3sh commented 3 months ago

Is there a fix planned for this ? This error is unfriendly and confusing and the suggested "fix" in the error message does not always work.

I am surprised installing MAUI workload from VS 2022 does not install maui-tizen, if it is really required, Why is it so ? The builds from Visual Studio still do not work even if you install maui-tizen like the error message asks you to, i.e. via dotnet workload restore. This makes it very ugly to have MAUI enabled in managed environments where the developers may not necessarily have access to a privileged shell.

Why is barrier to entry so high 😞

SilenceCZ commented 3 months ago

@avin3sh Hey, if you’re on Mac, this fixed it for me: "To use Visual Studio for Mac with .NET 8, enable the Visual Studio > Preferences > Other > Preview Features > Use the .NET 8 SDK if installed (requires restart) checkbox."

avin3sh commented 3 months ago

Thanks @SilenceCZ -- I did see your earlier suggestion, unfortunately in my case we are using Windows platform and toggling preview features did not help. We already have .NET 8 SDK in our environment, btw.

What concerns me more (1) Enabling MAUI Workload through Visual Studio "repair" option is not enough -- shouldn't it install all the necessary workloads needed to build a MAUI app ? It installs maui-windows, maccatalyst, ios and android and looks like these are not sufficient to build the app on Windows -- even if you are not targeting Tizen

(2) The fix in the error message does not work - dotnet workload restore was not sufficient. I had to explicitly install dotnet workload install maui-tizen, dotnet workload install maui and then finally dotnet workload restore and then exit and re-launch Visual Studio Window.

It could be that the issue lingers somewhere in VS/MSBUILD integration, therefore not quite relevant as dotnet SDK issue, but the message could have been more helpful.