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 build does not run without sudo #10553

Open BananchickPasha opened 5 years ago

BananchickPasha commented 5 years ago

When i write dotnet build in any project, I have this error:

> dotnet build
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 80.46 ms for /home/banan/programming/dotnet/test3/test3.csproj.
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018: System.UnauthorizedAccessException: Access to the path '/home/banan/programming/dotnet/test3/obj/Debug/netcoreapp3.0/t
est3' is denied. [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:  ---> System.IO.IOException: Permission denied [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    --- End of inner exception stack trace --- [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/
home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/home/banan/programmi
ng/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options) [/home/banan/programming/do
tnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Fil
eOptions options) [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/home/banan/progra
mming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/home/banan/programming/dotn
et/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.BinaryUtils.CopyFile(String sourcePath, String destinationPath) [/home/banan/pro
gramming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestination
FilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom) [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/home/banan/prog
ramming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingCon
text taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/banan/programming/dotnet/test3/test3.csproj]

Build FAILED.

/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018: System.UnauthorizedAccessException: Access to the path '/home/banan/programming/dotnet/test3/obj/Debug/netcoreapp3.0/t
est3' is denied. [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:  ---> System.IO.IOException: Permission denied [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    --- End of inner exception stack trace --- [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/
home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/home/banan/programmi
ng/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options) [/home/banan/programming/do
tnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Fil
eOptions options) [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/home/banan/progra
mming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/home/banan/programming/dotn
et/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.BinaryUtils.CopyFile(String sourcePath, String destinationPath) [/home/banan/pro
gramming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestination
FilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom) [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/home/banan/programming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/home/banan/prog
ramming/dotnet/test3/test3.csproj]
/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingCon
text taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/banan/programming/dotnet/test3/test3.csproj]
    0 Warning(s)
    1 Error(s)

but when I run the same command under root, all works OK:

> sudo dotnet build
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 79.49 ms for /home/banan/programming/dotnet/test3/test3.csproj.
  test3 -> /home/banan/programming/dotnet/test3/bin/Debug/netcoreapp3.0/test3.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.35

Another problem is that when I write sudo dotnet run, It cannot find some files

> sudo dotnet run
System.ComponentModel.Win32Exception (2): No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, B
oolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd,
Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Microsoft.DotNet.Cli.Utils.Command.Execute()
   at Microsoft.DotNet.Tools.Run.RunCommand.Execute()
   at Microsoft.DotNet.Tools.Run.RunCommand.Run(String[] args)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

What can it be? Here is my dotnet info:

> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     nixos
 OS Version:  19.09.736.9bbad4c6254
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  3.0.100 [/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.0.0 [/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.0.0 [/nix/store/zbll97grz8m6x04b9xsflr3kq7d85qb4-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
livarcocc commented 5 years ago

Do you have write permission as your user to the project folder?

Can you try that in a separate project in a different location on the machine?

BananchickPasha commented 5 years ago

I have the same error at different location (~/dotnet) and don't have this error with old 2.2 sdk:

> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.401
 Commit:    729b316c13

Runtime Environment:
 OS Name:     nixos
 OS Version:  19.09.736.9bbad4c6254
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/v5dw1mbw3y1ia8ybv9jyhp04kr4lx936-dotnet-sdk-2.2.401/sdk/2.2.401/

Host (useful for support):
  Version: 2.2.6
  Commit:  7dac9b1b51

.NET Core SDKs installed:
  2.2.401 [/nix/store/v5dw1mbw3y1ia8ybv9jyhp04kr4lx936-dotnet-sdk-2.2.401/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.6 [/nix/store/v5dw1mbw3y1ia8ybv9jyhp04kr4lx936-dotnet-sdk-2.2.401/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.6 [/nix/store/v5dw1mbw3y1ia8ybv9jyhp04kr4lx936-dotnet-sdk-2.2.401/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.6 [/nix/store/v5dw1mbw3y1ia8ybv9jyhp04kr4lx936-dotnet-sdk-2.2.401/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
dasMulli commented 5 years ago

This is likely a duplicate of https://github.com/dotnet/core-setup/issues/8511, about to be fixed by https://github.com/dotnet/core-setup/pull/8510 TL;DR the app host is copied from the global install location which may not include writable permissions and thus the task that modifies the app host fails.

BananchickPasha commented 5 years ago

I even set 777 permissions both for dotnet installation and project dirs, but it didn't help, I have the same error.

wli3 commented 5 years ago

You are using nix, I find there are many restrictions from nix and we are not familiar with it. We would need some time to investigate

tssm commented 4 years ago

I'm seeing a similar problem in macOS + Nix. Version 2.2 works without problem. I'm new to .Net, but maybe I'm able to help fixing it. As detailed in the StackOverflow question my hypothesis is that I need access to some path outside the Nix store but setting $TMPDIR doesn't work, neither does $DOTNET_BUNDLE_EXTRACT_BASE_DIR

briantliao commented 4 years ago

I am having a similar problem, running dotnet run gives me

/usr/local/share/dotnet/sdk/3.1.201/Microsoft.Common.CurrentVersion.targets(2081,5): warning MSB3101: Could not write state file "obj/Debug/netcoreapp3.1/try-argu.fsprojAssemblyReference.cache". Access to the path '/Users/btl787/00-local/01-programming/04-fsharp/08-argu/try-argu/obj/Debug/netcoreapp3.1/try-argu.fsprojAssemblyReference.cache' is denied. [/Users/btl787/00-local/01-programming/04-fsharp/08-argu/try-argu/try-argu.fsproj]
/usr/local/share/dotnet/sdk/3.1.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.GenerateAssemblyInfo.targets(116,5): error MSB3491: Could not write lines to file "obj/Debug/netcoreapp3.1/try-argu.AssemblyInfoInputs.cache". Access to the path '/Users/btl787/00-local/01-programming/04-fsharp/08-argu/try-argu/obj/Debug/netcoreapp3.1/try-argu.AssemblyInfoInputs.cache' is denied. [/Users/btl787/00-local/01-programming/04-fsharp/08-argu/try-argu/try-argu.fsproj]
/usr/local/share/dotnet/sdk/3.1.201/Microsoft.Common.CurrentVersion.targets(5199,5): error MSB3491: Could not write lines to file "obj/Debug/netcoreapp3.1/try-argu.fsproj.FileListAbsolute.txt". Access to the path '/Users/btl787/00-local/01-programming/04-fsharp/08-argu/try-argu/obj/Debug/netcoreapp3.1/try-argu.fsproj.FileListAbsolute.txt' is denied. [/Users/btl787/00-local/01-programming/04-fsharp/08-argu/try-argu/try-argu.fsproj]

The build failed. Fix the build errors and run again.

while sudo dotnet run has no errors and prints "Hello World".

romantitov commented 4 years ago

I have the same issue with Ubuntu 18.04.5 and dotnet core 3.1.100

AustEcon commented 4 years ago

Same issue Ubuntu 20.04 - Core 3.1.403 (error MSB4018: ---> System.IO.IOException: Permission denied ...) Using chmod 777 or chown to current user on entire repo doesn't help. But is giving "Permission denied" to files within the repo still?

Sudo dotnet build works though... But this means that I cannot use my IDE on Linux for much of anything really...

.NET Core SDK (reflecting any global.json):
 Version:   3.1.403
 Commit:    9e895200cd

Runtime Environment:
 OS Name:     pop
 OS Version:  20.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.403/

Host (useful for support):
  Version: 3.1.9
  Commit:  774fc3d6a9

.NET Core SDKs installed:
  3.1.403 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Only way I can make it work is by doing chmod 775 to repo + /usr/share but I don't want to instruct other consumers of this code to be doing things like that...

Does this qualify as a bug for ASP.NET core on linux? Or is this not supposed to be happening? If so what is the thing that I'm doing wrong? (I've tried the package manager + snap + the microsoft install script but all have the same issue)

sessio commented 3 years ago

Same issue here with WSL2 + ubuntu 20.04, 5.0 SDK installed like https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#2004- instructed.

sudo works.

pdebruin commented 3 years ago

The scripted install worked for me https://docs.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install

leandro-toledo-uux commented 2 years ago

For those who are running windows on a processor more than 1 core, probably will experience it in WSL2.

I solved just setting the processors=1 in .wslconfig.