dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.17k stars 1.34k forks source link

System.ComponentModel.Win32Exception (13): Permission denied (MacOS) #5437

Open JaggerJo opened 4 years ago

JaggerJo commented 4 years ago

Steps to reproduce

  1. Clone or create a Solution that contains at least one F# project. (I used https://github.com/AvaloniaCommunity/Avalonia.FuncUI)
  2. Download SolutionBuilder.zip
  3. Call BuildCoordinator.buildSolution(solutionPath: string) method or hardcode a solution path in Program.main

Expected behavior

Solution is compiled without errors.

Actual behavior

Compilation fails with error.

        /usr/local/share/dotnet/sdk/5.0.100-preview.5.20279.10/FSharp/Microsoft.FSharp.Targets(279,9): error MSB6003: The specified task executable "fsc.exe" could not be run. System.ComponentModel.Win32Exception (13): Permission denied
        /usr/local/share/dotnet/sdk/5.0.100-preview.5.20279.10/FSharp/Microsoft.FSharp.Targets(279,9): error MSB6003:    at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
        /usr/local/share/dotnet/sdk/5.0.100-preview.5.20279.10/FSharp/Microsoft.FSharp.Targets(279,9): error MSB6003:    at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
        /usr/local/share/dotnet/sdk/5.0.100-preview.5.20279.10/FSharp/Microsoft.FSharp.Targets(279,9): error MSB6003:    at System.Diagnostics.Process.Start()
        /usr/local/share/dotnet/sdk/5.0.100-preview.5.20279.10/FSharp/Microsoft.FSharp.Targets(279,9): error MSB6003:    at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands)
        /usr/local/share/dotnet/sdk/5.0.100-preview.5.20279.10/FSharp/Microsoft.FSharp.Targets(279,9): error MSB6003:    at FSharp.Build.Fsc.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) in F:\workspace\_work\1\s\src\fsharp\FSharp.Build\Fsc.fs:line 561
        /usr/local/share/dotnet/sdk/5.0.100-preview.5.20279.10/FSharp/Microsoft.FSharp.Targets(279,9): error MSB6003:    at Microsoft.Build.Utilities.ToolTask.Execute()

Environment data

msbuild /version output:

Microsoft (R) Build Engine version 16.6.0-ci-20224-01 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

16.6.0.22401%                                                                   

OS info: macOS Catalina (10.15.05)

Additional info

.NET SDKs installed:
  2.1.202 [/usr/local/share/dotnet/sdk]
  2.2.207 [/usr/local/share/dotnet/sdk]
  3.0.102 [/usr/local/share/dotnet/sdk]
  3.1.101 [/usr/local/share/dotnet/sdk]
  3.1.200 [/usr/local/share/dotnet/sdk]
  5.0.100-preview.5.20279.10 [/usr/local/share/dotnet/sdk]
JaggerJo commented 4 years ago

@BenVillalobos let me know if you need further information.

JaggerJo commented 3 years ago

@BenVillalobos is there anything new / did you have a chance to look at this ?

This is kind of a blocking issue for me, so if there is anything else I should try or look at please let me know.

benvillalobos commented 3 years ago

@JaggerJo I'll be taking a look at this soon!

JaggerJo commented 3 years ago

@BenVillalobos Great!

I noticed that the Permission denied exception gets thrown becauss ‘msbuild’ tries to execute ‘fsc.exe’ directly (instead via ‘’dotnet ...’).

Maybe an environment variable is missing - I’d somehow assume it has a correct default value..

Looking forward to your findings!

benvillalobos commented 3 years ago

@JaggerJo Jumping back on this train, I'm having trouble repro'ing the issue. A whole lot of

C:\Program Files\dotnet\sdk\5.0.100-preview.7.20366.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(115,5): error MSB4018: The "AllowEmptyTelemetry" task failed unexpectedly.
C:\Program Files\dotnet\sdk\5.0.100-preview.7.20366.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(115,5): error MSB4018: System.TypeLoadException: Could not load type 'System.Environment' from assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

that I'm unfamiliar with.

While I get that sorted out, I'm fairly certain this is related to fsc as you mentioned. Are you using MSBuildLocator here?

JaggerJo commented 3 years ago

@JaggerJo Jumping back on this train, I'm having trouble repro'ing the issue. A whole lot of

C:\Program Files\dotnet\sdk\5.0.100-preview.7.20366.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(115,5): error MSB4018: The "AllowEmptyTelemetry" task failed unexpectedly.
C:\Program Files\dotnet\sdk\5.0.100-preview.7.20366.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(115,5): error MSB4018: System.TypeLoadException: Could not load type 'System.Environment' from assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

that I'm unfamiliar with.

Hmm, that's strange. The error is also reproducible with any other SDK version I tried (3.1.200 for example).

While I get that sorted out, I'm fairly certain this is related to fsc as you mentioned. Are you using MSBuildLocator here ?

Basically, I've ported the parts I need to F# (Find SDK path, Set Env Variables and intercept assembly loading). Just to make sure I did not miss something important I just fetched MSBuildLocator and tried to build an F# Project with it. (failure)

By now I suspect I'm (and the sample projects) are missing some configuration (Environment?) variables that are only needed by F# related targets.