question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet build does not run without sudo

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
sessiocommented, Apr 24, 2021

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.

1reaction
leandro-toledo-uuxcommented, Jul 29, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I run dotnet on ubuntu without using sudo?
1 Answer. One possibility is to use mono instead of dotnet . It's an open source implementation of the . NET framework and...
Read more >
Elevated access for dotnet commands - .NET CLI
The following commands can be run elevated: dotnet tool commands, such as dotnet tool install. dotnet run --no-build; dotnet-core-uninstall.
Read more >
How do you install .Net Core on Ubuntu without using sudo?
Running dotnet from the tar.gz works just fine for me on Ubuntu 14. Running from the tar.gz or building from source does not...
Read more >
Dotnet commands requires sudo to run
I installed dotnet core on Pop OS. Unless, I use sudo dotnet run, it will give an access denied error. Has anyone encountered...
Read more >
sudo doesn't have access to globally installed software
Hm, I tried updating the path. Still not working for some reason. I ran sudo env "PATH=$PATH:/home/mrhoden/.dotnet/tools" then tried sudo dotnet ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found