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.73k stars 1.07k forks source link

dotnet workload command should include elevation #18585

Open lutzroeder opened 3 years ago

lutzroeder commented 3 years ago

The error message for requiring a workload install shows a command line that will result in another error on macOS:

~/Projects/maui-workload-test: dotnet build test.csproj                                                
Microsoft (R) Build Engine version 17.0.0-preview-21323-02+67ba2dfd7 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21326.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(33,5): error NETSDK1147: To build this project, the following workloads must be installed: microsoft-android-sdk-full maui-core microsoft-net-runtime-mono-tooling [~/Projects/maui-workload-test/test.csproj]
/usr/local/share/dotnet/sdk/6.0.100-preview.7.21326.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(33,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload install microsoft-android-sdk-full maui-core microsoft-net-runtime-mono-tooling [~/Projects/maui-workload-test/test.csproj]
~/Projects/maui-workload-test: dotnet workload install microsoft-android-sdk-full
Inadequate permissions to access, please elevate to run this command.
dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

sfoslund commented 3 years ago

This will be fixed by @joeloff's work. Once we have a admin installer it will be used automatically and elevate when needed. Closing as we don't need to track this separately from the admin installer.

joeloff commented 3 years ago

My engine is for MSIs, not for non-Windows systems. I don't think we scoped automatic elevation for any other OS platform for .NET 6. See dotnet/sdk#14956.

sfoslund commented 3 years ago

For mac/linux, I'm not sure that there's a way to detect from MSBuild (where this error is being thrown) that we would need to elevate in order to install the workload. @dsplaisted do you know if that's possible/ necessary?

dsplaisted commented 3 years ago

How do we detect that we need to generate the "Inadequate permissions to access" message? We might be able to do the same thing in the MSBuild task that generates the workload installation instructions.

joeloff commented 3 years ago

On Linux, does .NET wrap any calls into the stat/fstat APIs? That should allow you to query things like directories and get existing permissions. There's probably some extra work required, for example, a directory could be accessible to users within a group and the user doesn't have permissions, which doesn't imply elevation is required.

sfoslund commented 3 years ago

How do we detect that we need to generate the "Inadequate permissions to access" message?

We check if we can write to the resolved dotnet root: https://github.com/dotnet/sdk/blob/main/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallerFactory.cs#L75

joeloff commented 3 years ago

.NET does implement the system calls, e.g. https://github.com/dotnet/coreclr/blob/master/src/System.Private.CoreLib/shared/Interop/Unix/System.Native/Interop.Stat.cs

If you get EACCESS as a result of trying to write a file or create a directory then that would be a clear indication that there is a permission issue.

marcpopMSFT commented 3 years ago

Per workloads discussion, we're not going to prioritize this for .NET 6 as we'd have to tell we were on MacOS and figure out how to elevate which could be problematic. We considered during an improved error message telling them to elevate up front but that is backlog for net 6 rather than committed (so if we have time).

nosami commented 3 years ago

Please make sure that --print-download-link-only args don't require elevation.

sfoslund commented 3 years ago

Please make sure that --print-download-link-only args don't require elevation.

Good catch, I'll put out a fix for this and track the issue here: https://github.com/dotnet/sdk/issues/18738

nosami commented 3 years ago

Thanks @sfoslund!

Muhammadfaizann commented 2 years ago

any solution to this issue?

marcpopMSFT commented 2 years ago

We discussed in triage and are not aware of a way of elevating outside of windows which we already do. For non-windows, I'm not sure what we could do other than warn you that the command may require elevation during the original error.

Code-DJ commented 2 years ago

There is also this discrepancy where you keep getting the following message even if you sudo dotnet workload update: Updates are avaliable for the following workload(s): maui-maccatalyst maui-ios maui-android. Run dotnet workload update to get the latest.

The message doesn't show for sudo dotnet workload list but does show for dotnet workload list

datvm commented 1 year ago

After the most recent MacOS/VS update, I cannot update or install workloads. The same message shows up even though I am running it with elevated (admin) permission:

image

I also notice that dotnet command keeps printing the telemetry note (usually it only does once).

ITaluone commented 1 year ago

What about installing the workloads into a directory which does not require elevation?

This could also be beneficial for build servers where you can setup the needed workloads as step prior to dotnet build.

suchithm commented 11 months ago

Same issue with Dotnet workload install command. trying to update to .net8.0

Screenshot 2023-12-05 at 3 49 58 PM

Update: below command worked:

sudo dotnet workload install maui

MLB-BIOMETRIC commented 10 months ago

Any update on this outside Windows?

Deadvi5 commented 10 months ago

Any update on this? It would be interesting to know if there is a suggested way to do it

Ashishkumar5699 commented 8 months ago

try with sudo for mac and run as administrator for windows will works

monkeyK1n9 commented 7 months ago

@Ashishkumar5699 Thanks, this fixes the issue for me

rahou25 commented 6 months ago

Same issue with Dotnet workload install command. trying to update to .net8.0

Screenshot 2023-12-05 at 3 49 58 PM

Update: below command worked:

sudo dotnet workload install maui

this sudo dotnet workload install maui worked for me.

After trying several times to sudo or su first before running this command. Putting the sudo and the dotnet command in the same line worked. Just to mention this error occurred when trying to run dotnet maui project the 1st time on vscode for mac with c# dev kit.

tedonmain commented 1 week ago

sudo for mac