Skip to content

Commit b4701d2

Browse files
Update debug guide for local collector (#536)
Update debug docs
1 parent afe227b commit b4701d2

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

Documentation/Troubleshooting.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Hits file:'C:\Users\Marco\AppData\Local\Temp\coverlet.core_703263e9-21f0-4d1c-9c
6060
+---------+--------+--------+--------+
6161
```
6262

63-
## Use local build
63+
## Use local build(no collectors)
6464

6565
Sometimes is useful test local updated source to fix issue.
6666
You can "load" your local build using simple switch:
@@ -110,4 +110,81 @@ Test run for D:\git\Cake.Codecov\Source\Cake.Codecov.Tests\bin\Debug\netcoreapp2
110110
...
111111
```
112112

113-
In this way you can add `Debug.Launch()` inside coverlet source and debug.
113+
In this way you can add `Debug.Launch()` inside coverlet source and debug.
114+
115+
## Use local collectors build
116+
117+
To use/debug local collectors build we need to tell to our project to restore and use our local build nuget package.
118+
119+
1) Build local package
120+
```
121+
C:\git\coverlet\src\coverlet.collector (master -> origin)
122+
λ dotnet pack
123+
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
124+
Copyright (C) Microsoft Corporation. All rights reserved.
125+
126+
Restore completed in 50,28 ms for C:\git\coverlet\src\coverlet.collector\coverlet.collector.csproj.
127+
Restore completed in 50,28 ms for C:\git\coverlet\src\coverlet.core\coverlet.core.csproj.
128+
coverlet.core -> C:\git\coverlet\src\coverlet.core\bin\Debug\netstandard2.0\coverlet.core.dll
129+
coverlet.collector -> C:\git\coverlet\src\coverlet.collector\bin\Debug\netcoreapp2.0\coverlet.collector.dll
130+
Successfully created package 'C:\git\coverlet\bin\Debug\Packages\coverlet.collector.1.0.67.nupkg'.
131+
Successfully created package 'C:\git\coverlet\bin\Debug\Packages\coverlet.collector.1.0.67.snupkg'.
132+
```
133+
2) Add new `NuGet.Config` file on your test project/solution
134+
```
135+
<?xml version="1.0" encoding="utf-8"?>
136+
<configuration>
137+
<packageSources>
138+
<clear />
139+
<!-- Local path where you build packages -->
140+
<add key="localpackagesbuild" value="C:\git\coverlet\bin\Debug\Packages" />
141+
<!-- Defaul nuget feed -->
142+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
143+
<!-- Add all other needed feed -->
144+
</packageSources>
145+
</configuration>
146+
```
147+
3) Update nuget package in our test project
148+
```xml
149+
<Project Sdk="Microsoft.NET.Sdk">
150+
151+
<PropertyGroup>
152+
<TargetFramework>netcoreapp2.2</TargetFramework>
153+
<IsPackable>false</IsPackable>
154+
</PropertyGroup>
155+
156+
<ItemGroup>
157+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
158+
<PackageReference Include="xunit" Version="2.4.0" />
159+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
160+
<PackageReference Include="coverlet.collector" Version="1.0.67" /> <-- My local package version
161+
</ItemGroup>
162+
163+
<ItemGroup>
164+
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
165+
</ItemGroup>
166+
167+
</Project>
168+
169+
```
170+
4) Run test command
171+
```
172+
dotnet test XUnitTestProject1\ --collect:"XPlat Code Coverage"
173+
```
174+
175+
You can also attach/debug your code adding some line of code on collectors i.e.
176+
177+
Attach using vs "Attach to Process"
178+
```cs
179+
while(!System.Diagnostics.Debugger.IsAttached)
180+
{
181+
System.Threading.Thread.Sleep(1000);
182+
}
183+
```
184+
185+
Fire attach
186+
```cs
187+
System.Diagnostics.Debugger.Launch();
188+
```
189+
190+
**Every time you update code and rebuild new package remember to remove local nuget cache(`RMDIR "C:\Users\[winUser]\.nuget\packages\coverlet.collector" /S /Q`) otherwise you'll load old collector code because the package version wasn't changed**

build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
steps:
22
- task: UseDotNet@2
33
inputs:
4-
version: 2.2.300
4+
version: 2.2.401
55
displayName: Install .NET Core SDK
66

77
- script: dotnet restore

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "2.2.300"
3+
"version": "2.2.401"
44
}
55
}

0 commit comments

Comments
 (0)