Add msbuild instrumentation task debugging mode (#631)
Add msbuild instrumentation task debugging mode
This commit is contained in:
@@ -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(',');
|
||||
|
||||
Reference in New Issue
Block a user