Add msbuild instrumentation task debugging mode (#631)

Add msbuild instrumentation task debugging mode
This commit is contained in:
Marco Rossignoli
2019-12-03 10:06:49 +01:00
committed by GitHub
parent 63dbda8190
commit e1668028dc
2 changed files with 33 additions and 0 deletions
+13
View File
@@ -223,3 +223,16 @@ We can collect logs from trackers through an enviroment variable
```
When enabled, tracking event will be collected in log file near to module location.
File name will be something like `moduleName.dll_tracker.txt`
## Enable msbuild task instrumentation debugging
You can live attach and debug msbuild tasks with `COVERLET_MSBUILD_INSTRUMENTATIONTASK_DEBUG` env variable
```
set COVERLET_MSBUILD_INSTRUMENTATIONTASK_DEBUG=1
```
You'll get this message during test run
```
dotnet test -p:Include="[test_coverage.]" -p:Exclude="[*.Test.*]*" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=coverage.cobertura.xml
Coverlet msbuild instrumentation task debugging is enabled. Please attach debugger to process to continue
Process Id: 29228 Name: dotnet
```
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using Coverlet.Core;
@@ -97,8 +98,27 @@ namespace Coverlet.MSbuild.Tasks
_logger = new MSBuildLogger(Log);
}
private void WaitForDebuggerIfEnabled()
{
if (int.TryParse(Environment.GetEnvironmentVariable("COVERLET_MSBUILD_INSTRUMENTATIONTASK_DEBUG"), out int result) && result == 1)
{
Console.WriteLine("Coverlet msbuild instrumentation task debugging is enabled. Please attach debugger to process to continue");
Process currentProcess = Process.GetCurrentProcess();
Console.WriteLine($"Process Id: {currentProcess.Id} Name: {currentProcess.ProcessName}");
while (!Debugger.IsAttached)
{
System.Threading.Tasks.Task.Delay(1000).Wait();
}
Debugger.Break();
}
}
public override bool Execute()
{
WaitForDebuggerIfEnabled();
try
{
var includeFilters = _include?.Split(',');