cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.92k stars 731 forks source link

Unhandled exception: System.IO.IOException: Access to the path '...\build\tools\.store\.stage\ftb2snwd.f5x' is denied. #4315

Open paulomorgado opened 6 months ago

paulomorgado commented 6 months ago

Prerequisites

Cake runner

Cake Frosting

Cake version

4.0.0

Operating system

Windows

Operating system architecture

64-Bit

CI Server

No response

What are you seeing?

This happens when a Cake Frosting program has InstallTool with dotnet.

Visual Studio hold the ...\build\tools\.store\.stage hostage:

Installing tools...
Installing tool 'Microsoft.Sbom.DotNetTool'...
Configured Tools Folder: .../build/tools
Executing: "dotnet" tool list --tool-path ".../build/tools"
Package Id      Version      Commands
-------------------------------------
There are 0 dotnet tools installed
Checking for tool: microsoft.sbom.dotnettool
Running dotnet tool with operation Install: Microsoft.Sbom.DotNetTool...
Executing: "dotnet" tool install "Microsoft.Sbom.DotNetTool" --tool-path "C:/src/services-platform/connext/connector_demo_1/build/tools" --version 2.* --verbosity diagnostic
Unhandled exception: System.IO.IOException: Access to the path '...\build\tools\.store\.stage\by43pdyi.4ao' is denied.
   at System.IO.FileSystem.MoveDirectory(String sourceFullPath, String destFullPath, Boolean _)
   at System.IO.FileSystem.MoveDirectory(String sourceFullPath, String destFullPath)
   at Microsoft.DotNet.Cli.Utils.FileAccessRetrier.RetryOnMoveAccessFailure(Action action)
   at Microsoft.DotNet.Cli.ToolPackage.ToolPackageDownloader.<>c__DisplayClass8_0.<InstallPackage>b__0()
   at Microsoft.DotNet.Cli.TransactionalAction.Run[T](Func`1 action, Action commit, Action rollback)
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.<>c__DisplayClass20_0.<Execute>b__1()
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.RunWithHandlingInstallError(Action installAction)
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.Execute()
   at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)

This doesn't happen when using InstallTool with nuget.

What is expected?

This happens with this simple program:

public static class Program
{
    public static int Main(string[] args)
    {
        return new CakeHost()
            .InstallTool(new Uri("dotnet:?package=Microsoft.Sbom.DotNetTool&version=2.*"))
            .Run(args);
    }
}

Steps to Reproduce

This happens when a Cake Frosting program has InstallTool with dotnet.

Visual Studio hold the ...\build\tools\.store\.stage hostage.

This doesn't happen when using InstallTool with nuget.

Output log

Installing tools...
Installing tool 'Microsoft.Sbom.DotNetTool'...
Configured Tools Folder: .../build/tools
Executing: "dotnet" tool list --tool-path ".../build/tools"
Package Id      Version      Commands
-------------------------------------
There are 0 dotnet tools installed
Checking for tool: microsoft.sbom.dotnettool
Running dotnet tool with operation Install: Microsoft.Sbom.DotNetTool...
Executing: "dotnet" tool install "Microsoft.Sbom.DotNetTool" --tool-path "C:/src/services-platform/connext/connector_demo_1/build/tools" --version 2.* --verbosity diagnostic
Unhandled exception: System.IO.IOException: Access to the path '...\build\tools\.store\.stage\by43pdyi.4ao' is denied.
   at System.IO.FileSystem.MoveDirectory(String sourceFullPath, String destFullPath, Boolean _)
   at System.IO.FileSystem.MoveDirectory(String sourceFullPath, String destFullPath)
   at Microsoft.DotNet.Cli.Utils.FileAccessRetrier.RetryOnMoveAccessFailure(Action action)
   at Microsoft.DotNet.Cli.ToolPackage.ToolPackageDownloader.<>c__DisplayClass8_0.<InstallPackage>b__0()
   at Microsoft.DotNet.Cli.TransactionalAction.Run[T](Func`1 action, Action commit, Action rollback)
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.<>c__DisplayClass20_0.<Execute>b__1()
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.RunWithHandlingInstallError(Action installAction)
   at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.Execute()
   at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
paulomorgado commented 6 months ago

The immediate workaround is to add this to the csproj:

  <PropertyGroup Condition="'$(DesignTimeBuild)' == 'true'">
    <DefineConstants>$(DefineConstants);DESIGN_TIME_BUILD</DefineConstants>
  </PropertyGroup>

And this to the program:

public static class Program
{
    public static int Main(string[] args)
    {
        return new CakeHost()
#if !DESIGN_TIME_BUILD
            .InstallTool(new Uri("dotnet:?package=Microsoft.Sbom.DotNetTool&version=2.*"))
#endif
            .Run(args);
    }
}

Does not prevent it.