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.23k stars 1.35k forks source link

Killed build .binlogs are empty #3815

Open JohnTortugo opened 6 years ago

JohnTortugo commented 6 years ago

Problem: When I forcefully finish the execution of MSBuild.exe it doesn't flush any information to .binlog

Scenario to repro it:

I have a custom task like so:

public class TaskTeste : Task, ICancelableTask
{
    private readonly CancellationTokenSource cts = new CancellationTokenSource();

    public void Cancel() => cts.Cancel();

    public override bool Execute()
    {
        return cts.Token.WaitHandle.WaitOne(TimeSpan.FromSeconds(5));
    }
}

and I've a .proj file that uses it, like so:

<?xml version="1.0" encoding="utf-8"?>
<Project>
     <UsingTask TaskName="TaskTeste" AssemblyFile="C:\task-path\TaskTest.dll" />
      <Target Name="MyTarget">
              <TaskTeste />
      </Target>
</Project>

and I execute the project like this:

msbuild Testing.proj /bl:InnerCall.binlog

and after a few seconds I kill the msbuild.exe process using:

taskkill /F /IM msbuild.exe

After this, I expected the innerCall.binlog file to contain some information about the project execution. But it turns out the file is always empty. By the way, an InnerCall.ProjectImports.zip file is created, however that file isn't created when I let the process successfully finish.

Cc: @rainersigwald

KirillOsenkov commented 6 years ago

@JohnTortugo the reason InnerCall.ProjectImports.zip is not created in the normal case is because it is embedded directly into the .binlog and then deleted. The fact that the file stays there means the .binlog finalizer didn't run.

japj commented 5 years ago

@JohnTortugo have you tried without /f? I have seen that if you let msbuild handle the cancel gracefully (not forcing immediate exit/kill) then it has time to cancel running tasks and finalize things.