I'm working on generating coverage. One of the tests was taking a long time if the OpenCover filter was just +[*] so I've decided to add the assembly names. But this isn't an efficient approach as the assemblies may increase. I want to do something like extract the assembly name from UnitTestAssemblies and pass it on to filters as argument with the brackets and all.
The UnitTestAssembly.Filename gives Assembly1.Tests and I want the Assembly1 to be added as filter.
<ItemGroup>
<UnitTestAssemblies Include="$(ProjectRoot)\**\bin\$(Configuration)\*.Tests.dll" />
</ItemGroup>
<Exec Command="$(OpenCoverToolPath)\OpenCover.Console.exe
-target:$(NUnitToolPath)\nunit3-console.exe
-register
-targetargs:%(UnitTestAssemblies.FullPath)
-filter:"+[Assembly1]* +[Assembly2]*"
-output:$(somepath)\%(UnitTestAssemblies.Filename).coverage.xml"
ContinueOnError="true" Timeout="1800000"/>
I amn't sure if this approach is efficient but this worked for me.
<ItemGroup>
<UnitTestAssemblies>
<AssemblyName>+[$([System.String]::Copy('%(Filename)').Replace('.Tests', ''))]*</AssemblyName>
<UnitTestAssemblies>
</ItemGroup>
<PropertyGroup>
<AssemblyFilters>@(UnitTestAssemblies->'%(AssemblyName)'->Distinct(), ' ')</AssemblyFilters>
<PropertyGroup>
Then I passed $(AssemblyFilters)
as argument. -filters:"$(AssemblyFilters)"