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

[BUG] 'To build this project, the following workloads must be installed: maui-android', but the workload is already installed #37706

Closed
anpin opened this issue Jan 2, 2024 · 42 comments
Assignees
Labels
Area-Workloads needs team triage Requires a full team discussion untriaged Request triage from a team member

Comments

@anpin
Copy link

anpin commented Jan 2, 2024

Describe the bug

I'm not able to restore/ build MAUI project targeting net8.0-android on linux. The message says I need to install net8.0-android even though it is already installed.
image

To Reproduce

The repro is located here and it is using the nix package manager to setup developer environment with dotnet and userlocal files as per #18823.

git clone https://github.com/anpin/maui-on-nix
cd maui-on-nix
nix develop 
dotnet workload restore 
dotnet restore

Exceptions (if any)

"/home/a/projects/maui-on-nix/maui-on-nix.sln" (Restore target) (1) ->
                   "/home/a/projects/maui-on-nix/src/MauiOnNix.csproj" (_GenerateProjectRestoreGraph target) (2:7) ->
                   "/home/a/projects/maui-on-nix/src/MauiOnNix.csproj" (_GenerateProjectRestoreGraphPerFramework target) (2:9) ->
                   (_CheckForMissingWorkload target) ->
                     /nix/store/gm3ak3vgrx8qik40cnw28056i38hajsb-dotnet-sdk-8.0.100/sdk/8.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-android [/home/a/projects/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]
                   /nix/store/gm3ak3vgrx8qik40cnw28056i38hajsb-dotnet-sdk-8.0.100/sdk/8.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore [/home/a/projects/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]

Further technical details

.NET SDK:
 Version:           8.0.100
 Commit:            57efcf1350
 Workload version:  8.0.100-manifests.d75fd3e4

Runtime Environment:
 OS Name:     nixos
 OS Version:  24.05
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/gm3ak3vgrx8qik40cnw28056i38hajsb-dotnet-sdk-8.0.100/sdk/8.0.100/

.NET workloads installed:
 Workload version: 8.0.100-manifests.d75fd3e4
 [maui-android]
   Installation Source: SDK 8.0.100
   Manifest Version:    8.0.3/8.0.100
   Manifest Path:       /home/a/.dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.3/WorkloadManifest.json
   Install Type:        FileBased

 [maui-tizen]
   Installation Source: SDK 8.0.100
   Manifest Version:    8.0.3/8.0.100
   Manifest Path:       /home/a/.dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.3/WorkloadManifest.json
   Install Type:        FileBased

 [wasi-experimental]
   Installation Source: SDK 8.0.100
   Manifest Version:    8.0.0/8.0.100
   Manifest Path:       /nix/store/1i031mawznylm1plswjxfdyhcnxwgin2-dotnet-core-combined/sdk-manifests/8.0.100/microsoft.net.workload.mono.toolchain.current/8.0.0/WorkloadManifest.json
   Install Type:        FileBased


Host:
  Version:      8.0.0
  Architecture: x64
  Commit:       5535e31a71

.NET SDKs installed:
  8.0.100 [/nix/store/1i031mawznylm1plswjxfdyhcnxwgin2-dotnet-core-combined/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0 [/nix/store/1i031mawznylm1plswjxfdyhcnxwgin2-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0 [/nix/store/1i031mawznylm1plswjxfdyhcnxwgin2-dotnet-core-combined/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/nix/store/1i031mawznylm1plswjxfdyhcnxwgin2-dotnet-core-combined]

global.json file:
  Not found

binlog.zip

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Workloads untriaged Request triage from a team member labels Jan 2, 2024
@anpin
Copy link
Author

anpin commented Jan 17, 2024

not able to reproduce it in docker with ubuntu (the reproduction repo was updated with dockerfile), so it must be nixos specific

@anpin
Copy link
Author

anpin commented May 8, 2024

@baronfel can you give any advise on how to investigate it further please?

@SylvainGantois
Copy link

Same problem on Ubuntu

@anpin
Copy link
Author

anpin commented May 20, 2024

Same problem on Ubuntu

Interesting. Would you mind sharing how your environment is setup and if it is anywhere close to the docker file in my reproduction repo?

@SylvainGantois
Copy link

SylvainGantois commented May 20, 2024

ok, my bad, it actually worked but I had to:

  • follow the instructions here: Workload ID maui-android is not recognized #38171 (install via script and copy the sdk-manifests folder) files
  • remove net8.0-ios and net8.0-maccatalyst from the targets of the project
  • build using dotnet build, by using Rider I get the following:
    1>Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): Error NETSDK1147 : To build this project, the following workloads must be installed: maui-android To install these workloads, run the following command: dotnet workload restore 1>Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): Error NETSDK1147 : To build this project, the following workloads must be installed: maui-tizen To install these workloads, run the following command: dotnet workload restore

@anpin
Copy link
Author

anpin commented May 21, 2024

@GaijinFizz thanks for linking the issue, I was not aware of it. Looks to me like the the sdk ignores $DOTNET_ROOT/metadata/workloads/8.0.100/userlocal at some stage and instead of looking for installed workloads in $HOME/.dotnet looks at /usr/[lib|share]/dotnet which is not present on nixos. However, some users are reporting that the workaround used in the reproduction repo works for them, please see this thread

@anpin
Copy link
Author

anpin commented May 21, 2024

Actually I'm wrong, by quickly searching for /usr/lib I have found that it comes from the $DOTNET_ROOT environment varaible

@SylvainGantois
Copy link

SylvainGantois commented May 21, 2024

@GaijinFizz thanks for linking the issue, I was not aware of it. Looks to me like the the sdk ignores $DOTNET_ROOT/metadata/workloads/8.0.100/userlocal at some stage and instead of looking for installed workloads in $HOME/.dotnet looks at /usr/[lib|share]/dotnet which is not present on nixos. However, some users are reporting that the workaround used in the reproduction repo works for them, please see this thread

I had to create /usr/share/dotnet before copying sdk-manifests, it's worth a try :)

@Mr-MooMoo
Copy link

Mr-MooMoo commented May 26, 2024

I think i face the same problem.

'dotnet workload install aspire" (or any other dotnet workload install or update command) results in:
Workload installation failed: Read-only file system : '/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/metadata/workloads/8.0.300/InstallState',

although I have a file 'userlocal' present @ '/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/metadata/workloads/8.0.300/userlocal' , which (as far as i understood) should force sdk to install workloads in my $HOME/.dotnet folder..?

@baronfel
Copy link
Member

@Mr-MooMoo this is a side effect of the workloads sets feature we're working on I believe. @dsplaisted / @Forgind do we check where the install state should be written to for the user local workload scenario? If not I think we should.

@anpin
Copy link
Author

anpin commented May 27, 2024

@Mr-MooMoo do you have $DOTNET_ROOT env variable set?

In my case installation completes successfully and files are present in ~/.dotnet, but sdk fails to run restore/build/etc

@Mr-MooMoo
Copy link

@anpin yes; it points to the (correct) nix-store path:

❯ echo $DOTNET_ROOT
/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined

@dsplaisted
Copy link
Member

FYI @marcpopMSFT @baronfel Looks like the workload install state doesn't work with the user local workload setting.

@marcpopMSFT marcpopMSFT added the needs team triage Requires a full team discussion label May 28, 2024
@marcpopMSFT
Copy link
Member

Triage: For the original issue, the binlog lists that it's trying to find rc2 workloads but the --info output lists the 8.0.3 version installed. The build does full resolution. The list command just looks at the install records.

@anpin the --info output looks like we're finding manifests from a couple of different locations where the manifests are found but I would bet you have rc2 manifests under the dotnet location where the sdk is found. Can you check that?

CC @tmds as there may be something off here with how user local installs are working currently. We may need to take a look at --info and list and ensure they are correctly pulling data for user local installs. There is also the issue the other user hit around access to install state for user local installs.

@tmds
Copy link
Member

tmds commented May 29, 2024

The user local installs are used for an SDK band when there is a file at $DOTNET_ROOT/metadata/workloads/X.0.Y00/userlocal. (note: the last two digits of the versions are always 00, also when there are patch versions for the SDK).

I assume the bad situation could come from doing a "sudo" workload install for an SDK that has the userlocal file. It may cause some files being written (and directories created) as root which then are no longer accessible for the regular user.

Are there some steps here to reproduce the issue? Preferably in a container.

User local installs work fine for me with the Fedora source-built SDK:

$ dotnet workload list

Installed Workload Id      Manifest Version      Installation Source
--------------------------------------------------------------------
aspire                     8.0.1/8.0.100         SDK 8.0.100        

Use `dotnet workload search` to find additional workloads to install.

@SylvainGantois
Copy link

@tmds could you please try with a maui workload? It seems not all workloads are affected (#38171)

@tmds
Copy link
Member

tmds commented May 29, 2024

maui workloads can't be installed on source-built SDKs: #38171 (comment). Until this get resolved, the suggested workaround is to install a Microsoft SDK: #38171 (comment).

@SylvainGantois
Copy link

I do not understand, I installed .net8.0 with the MS script but the maui workload restore did not work out of the box, I had to duplicate the sdk-manifests folder.

@anpin
Copy link
Author

anpin commented May 29, 2024

@marcpopMSFT here is updated info. I removed ~/.dotnet and used more recent sdk. (All the files below are included in the reproduction repo from original post)

dotnet workload restore -v diag --project ./maui-on-nix.sln > restore_log.txt 2>&1

restore_log.txt

> dotnet --info
.NET SDK:
 Version:           8.0.204
 Commit:            c338c7548c
 Workload version:  8.0.200-manifests.9f663350

Runtime Environment:
 OS Name:     nixos
 OS Version:  24.11
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/sdk/8.0.204/

.NET workloads installed:
 [maui-android]
   Installation Source: SDK 8.0.200
   Manifest Version:    8.0.3/8.0.100
   Manifest Path:       /nix/store/zxq761i5cj7d9ainch7d3g35w2b9c4sj-dotnet-core-combined/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.3/WorkloadManifest.json
   Install Type:        FileBased


Host:
  Version:      8.0.4
  Architecture: x64
  Commit:       2d7eea2529

.NET SDKs installed:
  8.0.204 [/nix/store/zxq761i5cj7d9ainch7d3g35w2b9c4sj-dotnet-core-combined/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.4 [/nix/store/zxq761i5cj7d9ainch7d3g35w2b9c4sj-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.4 [/nix/store/zxq761i5cj7d9ainch7d3g35w2b9c4sj-dotnet-core-combined/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/nix/store/zxq761i5cj7d9ainch7d3g35w2b9c4sj-dotnet-core-combined]

global.json file:
  Not found

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

Download .NET:
  https://aka.ms/dotnet/download
> tree -paug ~/.dotnet > contents_of_.dotnet.txt

contents_of_.dotnet.txt

> tree -paug $DOTNET_ROOT > contents_of_dotnet_root.txt

contents_of_dotnet_root.txt

> dotnet restore -bl
  Determining projects to restore...
/nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/sdk/8.0.204/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-android [/home/a/projects/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]
/nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/sdk/8.0.204/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore [/home/a/projects/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]

msbuild.zip

@anpin
Copy link
Author

anpin commented May 29, 2024

@tmds here is a docker file to run reproduction repo. AFAIK nixos uses binary sdk by default with an option to use source built sdk NixOS/nixpkgs#190129

FROM nixos/nix:latest
RUN git clone https://github.com/anpin/maui-on-nix
WORKDIR /maui-on-nix
RUN nix --extra-experimental-features "nix-command flakes" develop --command bash -c "\
    dotnet workload restore -v detailed && \
    dotnet restore -v detailed && \
    dotnet build -v detailed"
...
.0.204/sdk/8.0.204/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets" from project "/maui-on-nix/src/MauiOnNix.csproj" (target "_CheckForUnsupportedTargetPlatformIdentifier" depends on it):
       Using "ShowMissingWorkloads" task from assembly "/nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/sdk/8.0.204/Sdks/Microsoft.NET.Sdk/targets/../tools/net8.0/Microsoft.NET.Build.Tasks.dll".
       Task "ShowMissingWorkloads"
   2:9>/nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/sdk/8.0.204/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-android [/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]
/nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/sdk/8.0.204/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore [/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]
       Done executing task "ShowMissingWorkloads" -- FAILED.
   2:9>Done building target "_CheckForMissingWorkload" in project "MauiOnNix.csproj" -- FAILED.
   2:9>Done Building Project "/maui-on-nix/src/MauiOnNix.csproj" (_GenerateProjectRestoreGraphPerFramework target(s)) -- FAILED.
   2:7>Done executing task "MSBuild" -- FAILED.
   2:7>Done building target "_GenerateProjectRestoreGraphAllFrameworks" in project "MauiOnNix.csproj" -- FAILED.
   2:7>Done Building Project "/maui-on-nix/src/MauiOnNix.csproj" (_GenerateProjectRestoreGraph target(s)) -- FAILED.
     1>Done executing task "MSBuild" -- FAILED.
     1>Done building target "_GenerateRestoreGraph" in project "maui-on-nix.sln" -- FAILED.
     1>Done Building Project "/maui-on-nix/maui-on-nix.sln" (Restore target(s)) -- FAILED.

Build FAILED.

       "/maui-on-nix/maui-on-nix.sln" (Restore target) (1) ->
       "/maui-on-nix/src/MauiOnNix.csproj" (_GenerateProjectRestoreGraph target) (2:7) ->
       "/maui-on-nix/src/MauiOnNix.csproj" (_GenerateProjectRestoreGraphPerFramework target) (2:9) ->
       (_CheckForMissingWorkload target) ->
         /nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/sdk/8.0.204/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-android [/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]
       /nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/sdk/8.0.204/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore [/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.37
Error: building at STEP "RUN nix --extra-experimental-features "nix-command flakes" develop --command bash -c "    dotnet workload restore -v detailed &&     dotnet restore -v detailed &&     dotnet build -v detailed"": while running runtime: exit status 1

@tmds
Copy link
Member

tmds commented May 29, 2024

@tmds here is a docker file to run reproduction repo. AFAIK nixos uses binary sdk by default with an option to use source built sdk NixOS/nixpkgs#190129

Thanks. I reproduced the issue and this is the root cause:

In my /nix/store I got a userlocal file at /nix/store/zxq761i5cj7d9ainch7d3g35w2b9c4sj-dotnet-core-combined/metadata/workloads/8.0.200/userlocal.

However, when the dotnet restore command runs, it tries to find userlocal at /nix/store/h1cjcq31jnhl5g8z7vg16k1vhmyadani-dotnet-sdk-8.0.204/metadata/workloads/8.0.200/userlocal.

When I manually create a file at the latter location, the dotnet restore command no longer fails.

@Mr-MooMoo
Copy link

I think dotnet restore and dotnet workload update are two separate issues.

Dotnet Info Output:

❯ dotnet --info
.NET SDK:
 Version:           8.0.300
 Commit:            326f6e68b2
 Workload version:  8.0.300-manifests.c1c70047
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     nixos
 OS Version:  24.11
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/8y83na7h81fw5kr1msmjc7rvx329djp0-dotnet-sdk-8.0.300/sdk/8.0.300/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.5
  Architecture: x64
  Commit:       087e15321b

.NET SDKs installed:
  7.0.409 [/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/sdk]
  8.0.300 [/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.19 [/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.5 [/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.19 [/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.5 [/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined]

global.json file:
  Not found

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

Download .NET:
  https://aka.ms/dotnet/download

and dotnet workload update seems to use the correct path (sdk path)

❯ dotnet workload update

No workloads installed for this feature band. To update workloads installed with earlier SDK versions, include the --from-previous-sdk option.
Skipping NuGet package signature verification.
Updated advertising manifest microsoft.net.workload.emscripten.net7.
Updated advertising manifest microsoft.net.sdk.tvos.
Updated advertising manifest microsoft.net.sdk.android.
Updated advertising manifest microsoft.net.sdk.maui.
Updated advertising manifest microsoft.net.workload.emscripten.net6.
Updated advertising manifest microsoft.net.sdk.macos.
Updated advertising manifest microsoft.net.sdk.maccatalyst.
Updated advertising manifest microsoft.net.sdk.ios.
Updated advertising manifest microsoft.net.workload.mono.toolchain.current.
Updated advertising manifest microsoft.net.workload.mono.toolchain.net6.
Updated advertising manifest microsoft.net.workload.emscripten.current.
Updated advertising manifest microsoft.net.sdk.aspire.
Updated advertising manifest microsoft.net.workload.mono.toolchain.net7.
No workloads installed for this feature band. To update workloads installed with earlier SDK versions, include the --from-previous-sdk option.
Installing workload manifest microsoft.net.sdk.android version 34.0.95...
Installing workload manifest microsoft.net.sdk.ios version 17.2.8053...
Installing workload manifest microsoft.net.sdk.maccatalyst version 17.2.8053...
Installing workload manifest microsoft.net.sdk.macos version 14.2.8053...
Installing workload manifest microsoft.net.sdk.maui version 8.0.21...
Installing workload manifest microsoft.net.sdk.tvos version 17.2.8053...
Installing workload manifest microsoft.net.workload.mono.toolchain.current version 8.0.6...
Installing workload manifest microsoft.net.workload.emscripten.current version 8.0.6...
Installing workload manifest microsoft.net.workload.emscripten.net6 version 8.0.6...
Installing workload manifest microsoft.net.workload.emscripten.net7 version 8.0.6...
Installing workload manifest microsoft.net.workload.mono.toolchain.net6 version 8.0.6...
Installing workload manifest microsoft.net.workload.mono.toolchain.net7 version 8.0.6...
Installing workload manifest microsoft.net.sdk.aspire version 8.0.1...
Workload installation failed. Rolling back installed packs...
Workload update failed: Read-only file system : '/nix/store/g2mws5h1b3n08mfcxplfa98mf0rgr68p-dotnet-core-combined/metadata/workloads/8.0.300/InstallState'

@tmds
Copy link
Member

tmds commented May 29, 2024

I think dotnet restore and dotnet workload update are two separate issues.

The problem is that these two commands go look for the userlocal file at different location.

The dotnet workload command finds it under ...-dotnet-core-combined, and then it does a user local install.
The dotnet restore command doesn't find it under ...-dotnet-sdk-8.0.204 folder, and then says it doesn't find installed workloads.

@Mr-MooMoo
Copy link

But I don't even use dotnet restore at that point. And my workloads install fails nonetheless

@tmds
Copy link
Member

tmds commented May 29, 2024

But I don't even use dotnet restore at that point. And my workloads install fails nonetheless

Then your issue is different from this reproducer: #37706 (comment).

If you create an empty userlocal file at ...-dotnet-sdk-8.0.300/metadata/workloads/8.0.300/userlocal, does it behave different?

@tmds
Copy link
Member

tmds commented May 30, 2024

If you create an empty userlocal file at ...-dotnet-sdk-8.0.300/metadata/workloads/8.0.300/userlocal, does it behave different?

@Mr-MooMoo I assume this will fix your problem?

8y83na7h81fw5kr1msmjc7rvx329djp0-dotnet-sdk-8.0.300

As I understand, the files in these packages are the binaries that Microsoft built.

@anpin, as someone not familar with NixOS, I'm curious: does it require some sort of opt-in to use 3rd party binaries that were not built by the NixOS maintainers themselves?

The Microsoft built SDK won't include a userlocal file.
To have a consistent user experience, the NixOS package maintainer could add this file in these packages.

On the SDK side, it would be interesting to find out why dotnet restore and dotnet workload go look for the userlocal file at different locations. Probably it is related to how they try find the dotnet root directory. With the NixOS packages the directory containing the SDK is not under what the DOTNET_ROOT envvar is set to.

@anpin
Copy link
Author

anpin commented May 30, 2024

@tmds all binaries are statically linked into /nix/store/-- even you build them yourself and it is read-only. In this particular case we use a symlink to join multiple SDK versions into /nix/store/-dotnet-core-combined then create the userlocal files and set this path to $DOTNET_ROOT (here are contents_of_dotnet_root.txt) . As you pointed out the big question is why dotnet restore / build /etc doesn't respect the $DOTNET_ROOT while dotnet workload restore does.

@tmds
Copy link
Member

tmds commented May 30, 2024

Does it require some sort of opt-in to use 3rd party binaries that were not built by the NixOS maintainers themselves?

@anpin, I'm interested to learn this.

we use a symlink to join multiple SDK versions

I don't think anyone does this, so it's not surprising you are running into some issues with this layout.

As you pointed out the big question is why dotnet restore / build /etc doesn't respect the $DOTNET_ROOT while dotnet workload restore does.

Per https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#net-sdk-and-cli-environment-variables, DOTNET_ROOT is meant to specify the location of the .NET runtimes.

This doesn't say anything about SDKs.

For NixOS, the .NET 8.0.300 SDK resides in a directory: ...-dotnet-sdk-8.0.300/sdk/8.0.300 and the file ./metadata/workloads/8.0.300/userlocal is meant to configure that 8.0.300 SDK for userlocal install.

Since the userlocal file is meant for the SDK, in my opinion, it makes most sense for it to be in the ...-dotnet-sdk-8.0.300 directory instead of ...-dotnet-core-combined.

You can create that file in your packages as a temporary solution.

@tmds
Copy link
Member

tmds commented May 30, 2024

here are contents_of_dotnet_root.txt

Perhaps it would make sense to make metadata/workloads/8.0.300 a symlink as well?

@Mr-MooMoo
Copy link

Mr-MooMoo commented May 31, 2024

Sorry for my late response (i am on holiday currently); I tried your suggestions @tmds but unfortunately they don't work.

Steps:

  • I created a nix-shell with an overlay to sdk_8 (which is basically an isolated environment for devs - so i can force-add the 'userlocal' file, which I then checked is there),
  • dotnet --info shows both paths (sdk and runtime point to the same dir - see error message below)
  • dotnet workload update still fails with the same error (but this time using my new overlay path):

Workload update failed: Read-only file system : '/nix/store/dv2wivsriy4453rf1nmiqysg88k16rla-dotnet-sdk-8.0.300/metadata/workloads/8.0.300/InstallState'

So i guess (just a guess!) it's more likely that this is the problem (as mentioned before):

@Mr-MooMoo this is a side effect of the workloads sets feature we're working on I believe. @dsplaisted / @Forgind do we check where the install state should be written to for the user local workload scenario? If not I think we should.

FYI @marcpopMSFT @baronfel Looks like the workload install state doesn't work with the user local workload setting.

@tmds
Copy link
Member

tmds commented May 31, 2024

Workload update failed: Read-only file system : '/nix/store/dv2wivsriy4453rf1nmiqysg88k16rla-dotnet-sdk-8.0.300/metadata/workloads/8.0.300/InstallState'

The error says you are trying to install where the SDK lives, that is: it doesn't do a userlocal install.

I'm surprised that creating a userlocal file does not fix this issue.

Steps:

Can you write out the steps as commands so I can try to reproduce the issue?

@Mr-MooMoo
Copy link

Just from a little glimpse in sdk-source:

Workload-Installer seems to check if userlocal is present:

Source Link 1

But InstallState doesn't (just uses dotnetdir)

Source LInk 2

So, as the command always fails with while trying to write "InstallState", that seems possible.

@tmds

Sure, I created my nix shell:
shell.nix:

{ pkgs ? import <nixpkgs> { overlays = [ (import ./overlay.nix) ]; } }:

pkgs.mkShell {
  buildInputs = [ pkgs.dotnetCorePackages.sdk_8_0 ];
}

overlay.nix:

self: super: {
  dotnetCorePackages = super.dotnetCorePackages // {
    sdk_8_0 = super.dotnetCorePackages.sdk_8_0.overrideAttrs (oldAttrs: {
      installPhase = oldAttrs.installPhase + ''
        mkdir -p $out/metadata/workloads/8.0.300/
	touch $out/metadata/workloads/8.0.300/userlocal
      '';
    });
  };
}

then run nix-shell to enter this environment

@tmds
Copy link
Member

tmds commented Jun 5, 2024

@Mr-MooMoo, I reproduced the issue. It is different from the one @anpin ran into with the 8.0.2xx SDK.

@marcpopMSFT @dsplaisted @baronfel it seems that userlocal is broken in the 8.0.3xx band.

The issue can be reproduced with these commands (on any linux-x64 distro).

mkdir /tmp/repro
cd /tmp/repro
mkdir dotnet
cd dotnet
wget https://download.visualstudio.microsoft.com/download/pr/86497c4f-3dc8-4ee7-9f6a-9e0464059427/293d074c28bbfd9410f4db8e021fa290/dotnet-sdk-8.0.301-linux-x64.tar.gz
tar xvf *.tar.gz
mkdir -p metadata/workloads/8.0.300
touch metadata/workloads/8.0.300/userlocal
chmod -R -w .
export DOTNET_ROOT=$(pwd)
export PATH=$(pwd):$PATH
cd ..
mkdir home
cd home
export HOME=$(pwd)
dotnet workload update

@dsplaisted
Copy link
Member

@tmds thanks a lot for investigating and providing simple repro steps

@marcpopMSFT
Copy link
Member

Triage: I believe we're tracking the two core issues already through #41420 and dotnet/source-build#3242. Closing assuming those are tracking the issues identified here and we can reactivate if there's a third issue we missed.

@marcpopMSFT marcpopMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2024
@anpin
Copy link
Author

anpin commented Oct 11, 2024

still fails with rc1 :( #41735 (comment)

@kramer-e
Copy link

Same issue here with rc1 9.0.100-rc.1.24452.12

@kasperk81
Copy link
Contributor

how about rc2 (released recently)? https://dotnet.microsoft.com/en-us/download/dotnet/9.0

@kramer-e
Copy link

kramer-e commented Oct 11, 2024

Yeah, already saw that a new RC2 was released. I've installed the RC2 release and the MAUI workloads and it would build again.

Somehow the workloads were lost, dotnet workload list returned nothing.

@anpin
Copy link
Author

anpin commented Oct 12, 2024

For me RC2 does not fix it. Exactly the same as before.

> dotnet --info
.NET SDK:
 Version:           9.0.100-rc.2.24474.11
 Commit:            315e1305db
 Workload version:  9.0.100-manifests.4872d5d5
 MSBuild version:   17.12.0-preview-24473-03+fea15fbd1

Runtime Environment:
 OS Name:     nixos
 OS Version:  24.11
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/ckjmw8ahlv89vhn76rdqb04r7xkngz9c-dotnet-sdk-9.0.100-rc.2.24474.11/sdk/9.0.100-rc.2.24474.11/

.NET workloads installed:
 [maui-android]
   Installation Source: SDK 9.0.100-rc.2
   Manifest Version:    9.0.0-rc.2.24503.2/9.0.100-rc.2
   Manifest Path:       /home/a/.dotnet/sdk-manifests/9.0.100-rc.2/microsoft.net.sdk.maui/9.0.0-rc.2.24503.2/WorkloadManifest.json
   Install Type:        FileBased

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0-rc.2.24473.5
  Architecture: x64
  Commit:       990ebf52fc

.NET SDKs installed:
  9.0.100-rc.2.24474.11 [/nix/store/fa8svf3jpqs5jpx9jmigkvcpc7vflyqx-dotnet-core-combined/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [/nix/store/fa8svf3jpqs5jpx9jmigkvcpc7vflyqx-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [/nix/store/fa8svf3jpqs5jpx9jmigkvcpc7vflyqx-dotnet-core-combined/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/nix/store/fa8svf3jpqs5jpx9jmigkvcpc7vflyqx-dotnet-core-combined]

global.json file:
  Not found

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

Download .NET:
  https://aka.ms/dotnet/download
> dotnet workload list

Installed Workload Id      Manifest Version                     Installation Source
-----------------------------------------------------------------------------------
maui-android               9.0.0-rc.2.24503.2/9.0.100-rc.2      SDK 9.0.100-rc.2

Use `dotnet workload search` to find additional workloads to install.

> dotnet build
  Determining projects to restore...
/nix/store/ckjmw8ahlv89vhn76rdqb04r7xkngz9c-dotnet-sdk-9.0.100-rc.2.24474.11/sdk/9.0.100-rc.2.24474.11/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-android [/home/a/projects/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]
/nix/store/ckjmw8ahlv89vhn76rdqb04r7xkngz9c-dotnet-sdk-9.0.100-rc.2.24474.11/sdk/9.0.100-rc.2.24474.11/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore [/home/a/projects/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]

Build FAILED.

/nix/store/ckjmw8ahlv89vhn76rdqb04r7xkngz9c-dotnet-sdk-9.0.100-rc.2.24474.11/sdk/9.0.100-rc.2.24474.11/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: maui-android [/home/a/projects/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]
/nix/store/ckjmw8ahlv89vhn76rdqb04r7xkngz9c-dotnet-sdk-9.0.100-rc.2.24474.11/sdk/9.0.100-rc.2.24474.11/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload restore [/home/a/projects/maui-on-nix/src/MauiOnNix.csproj::TargetFramework=net8.0-android]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.76
> ls -al $DOTNET_ROOT/metadata/workloads/9.0.100/userlocal
.r--r--r-- 0 root 31 Dec  1969 /nix/store/fa8svf3jpqs5jpx9jmigkvcpc7vflyqx-dotnet-core-combined/metadata/workloads/9.0.100/userlocal

@anpin
Copy link
Author

anpin commented Oct 12, 2024

@marcpopMSFT would you mind re-opening this issue since it was not fixed?

@marcpopMSFT
Copy link
Member

I created a new bug since the original issue for this should be fixed. We can follow up there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Workloads needs team triage Requires a full team discussion untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

9 participants