Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"features": {
"ghcr.io/devcontainers/features/dotnet:2": {
"version": "10.0.100",
"additionalVersions": ["6.0.428", "8.0.416", "9.0.307"]
"additionalVersions": ["6.0.428", "8.0.416", "9.0.308"]
}
},

Expand Down
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
232 changes: 232 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
BuildConfiguration: debug
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

permissions:
checks: write
pull-requests: write

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
timeout-minutes: 30
permissions:
pull-requests: write
contents: read
checks: write

steps:
- uses: actions/checkout@v6.0.1
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

- name: Setup .NET 9.0
uses: actions/setup-dotnet@v5.0.1
with:
dotnet-version: 9.0.x
# source-url: https://pkgs.dev.azure.com/tonerdo/coverlet/_packaging/coverlet-nightly/nuget/v3/index.json
# env:
# NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_TOKEN }}

- name: Setup .NET 8.0
uses: actions/setup-dotnet@v5.0.1
with:
dotnet-version: 8.0.x
# source-url: https://pkgs.dev.azure.com/tonerdo/coverlet/_packaging/coverlet-nightly/nuget/v3/index.json
# env:
# NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_TOKEN }}

- name: create folders for artifacts
run: |
mkdir -p ./artifacts/bin
mkdir -p ./artifacts/package
mkdir -p ./artifacts/package/debug
mkdir -p ./artifacts/package/release
mkdir -p ./artifacts/log
mkdir -p ./artifacts/publish
mkdir -p ./artifacts/reports


- name: Restore dependencies
run: dotnet restore coverlet.sln

- name: Build
run: |
dotnet build coverlet.sln --no-restore -bl:build.binlog -c ${{env.BuildConfiguration}}
dotnet build coverlet.sln --no-restore -bl:build.binlog -c release
dotnet pack -c ${{env.BuildConfiguration}}
dotnet pack -c release

# - name: Archive production artifacts
# uses: actions/upload-artifact@v5
# with:
# name: dist-bin-and-packages
# retention-days: 5
# path: |
# artifacts/bin
# artifacts/package
# artifacts/publish
# artifacts/log
# *.binlog

# Fail if there are any failed tests
#
# We support all current LTS versions of .NET and Windows, Mac and Linux.
#
# To check for failing tests locally run `dotnet test`.

# test:
# name: Tests for .net core ${{ matrix.framework }} on ${{ matrix.os }}
# needs: build
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# os: [ubuntu-latest, windows-latest, macos-latest]
# framework: ['net9.0', 'net8.0']
# timeout-minutes: 30
# permissions:
# pull-requests: write
# steps:
# - name: Checkout
# uses: actions/checkout@v6.0.1
# with:
# fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

# - name: Setup .NET 9.0
# uses: actions/setup-dotnet@v5.0.1
# with:
# dotnet-version: 9.0.x

# - name: Setup dotnet 8.0
# uses: actions/setup-dotnet@v5.0.1
# with:
# dotnet-version: '8.0.x'

# - name: Download packages and artifacts
# uses: actions/download-artifact@v5
# with:
# name: dist-bin-and-packages

- run: |
echo "Test using script"
dotnet build-server shutdown
dotnet test ./test/coverlet.core.tests/coverlet.core.tests.csproj -c ${{env.BuildConfiguration}} --no-build -bl:test.core.binlog /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.projectsample]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" -- --results-directory "./artifacts/reports" --report-xunit-trx --report-xunit-trx-filename "coverlet.core.tests.trx" --diagnostic --diagnostic-output-directory "./artifacts/log/${{env.BuildConfiguration}}" --diagnostic-output-fileprefix "coverlet.core.tests"
dotnet build-server shutdown
dotnet test ./test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj -c ${{env.BuildConfiguration}} --no-build -bl:test.msbuild.binlog --results-directory:"./artifacts/reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*%2c[testgen_]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"./artifacts/log/${{env.BuildConfiguration}}/coverlet.msbuild.test.diag.log;tracelevel=verbose"
dotnet build-server shutdown
dotnet test ./test/coverlet.collector.tests/coverlet.collector.tests.csproj -c ${{env.BuildConfiguration}} --no-build -bl:test.collector.binlog /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.projectsample]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" --diag:"./artifacts/log/${{env.BuildConfiguration}}/coverlet.collector.test.diag.log;tracelevel=verbose"
dotnet build-server shutdown
dotnet test ./test/coverlet.integration.tests/coverlet.integration.tests.csproj -c ${{env.BuildConfiguration}} --no-build -bl:test.integration.binlog -- --results-directory "./artifacts/reports" --report-xunit-trx --report-xunit-trx-filename "coverlet.integration.tests.trx" --diagnostic --diagnostic-output-directory "./artifacts/log/${{env.BuildConfiguration}}" --diagnostic-output-fileprefix "coverlet.integration.tests"
name: Run unit tests with coverage
env:
MSBUILDDISABLENODEREUSE: 1

# - run: |
# echo "Test using script"
# dotnet build-server shutdown
# dotnet test ./test/coverlet.core.coverage.tests/coverlet.core.coverage.tests.csproj -c ${{env.BuildConfiguration}} --no-build -bl:test.core.coverage.binlog /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.projectsample]*" /p:ExcludeByAttribute="GeneratedCodeAttribute" -- --results-directory "./artifacts/reports" --report-xunit-trx --report-xunit-trx-filename "coverlet.core.coverage.tests.trx" --diagnostic --diagnostic-output-directory "./artifacts/log/${{env.BuildConfiguration}}" --diagnostic-output-fileprefix "coverlet.core.coverage.tests"
# name: Run unit test coverlet.core.coverage.tests
# if: success() && matrix.os == 'windows-latest'
# env:
# MSBUILDDISABLENODEREUSE: 1

- name: ReportGenerator
uses: danielpalme/ReportGenerator-GitHub-Action@5.5.1
if: success() && matrix.os == 'windows-latest'
with:
reports: ./artifacts/reports/**/*.cobertura.xml
assemblyfilters: -xunit*
targetdir: ./artifacts/reports
reporttypes: HtmlInline;Cobertura;MarkdownSummaryGithub;lcov

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2.9.4
if: success() && matrix.os == 'windows-latest' && github.event_name == 'pull_request'
with:
recreate: true
path: ./artifacts/reports/SummaryGithub.md

- name: Write to Job Summary
if: matrix.os == 'windows-latest'
run: cat ./artifacts/reports/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
shell: bash

- name: Upload Test Result Files
uses: actions/upload-artifact@v5
if: always()
with:
name: test-results-${{ matrix.os }}
path: ${{ github.workspace }}/artifacts/reports/**/*
retention-days: 5

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/linux@v2
if: ${{ !cancelled() && matrix.os == 'ubuntu-latest' }}
with:
files: |
${{ github.workspace }}/artifacts/reports/**/*.trx
${{ github.workspace }}/test/**/*.trx
check_name: "Unit Tests ${{ matrix.os }}"
comment_mode: failures
compare_to_earlier_commit: false

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/macos@v2.21.0
if: ${{ !cancelled() && matrix.os == 'macos-latest' }}
with:
files: |
${{ github.workspace }}/artifacts/reports/**/*.trx
${{ github.workspace }}/test/**/*.trx
check_name: "Unit Tests ${{ matrix.os }}"
comment_mode: failures
compare_to_earlier_commit: false

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/windows@v2.21.0
if: ${{ !cancelled() && matrix.os == 'windows-latest' }}
with:
files: |
${{ github.workspace }}/artifacts/reports/**/*.trx
${{ github.workspace }}/test/**/*.trx
check_name: "Unit Tests ${{ matrix.os }}"
comment_mode: failures
compare_to_earlier_commit: false

# - uses: bibipkins/dotnet-test-reporter@v1.6.1
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# comment-title: 'Unit Test Results ${{ matrix.os }}'
# results-path: |
# ./artifacts/reports/**/*.trx
# ./test/**/*.trx
# coverage-path: |
# ./artifacts/bin/**/*.cobertura.xml
# ./artifacts/reports/**/*.cobertura.xml
# ./test/**/*.cobertura.xml
# coverage-threshold: 80
# coverage-type: cobertura
# show-failed-tests-only: true
# show-test-output: true

# - name: Upload coverage report artifact
# if: success() && matrix.os == 'windows-latest'
# uses: actions/upload-artifact@v5
# with:
# name: CoverageReport.${{matrix.os}}.${{matrix.framework}} # Artifact name
# path: ./artifacts/CoverageReport # Directory containing files to upload
# overwrite: true
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ FolderProfile.pubxml
/NuGet.config
nuget.config
*.dmp
Playground*/
# extended playground
coverlet.MTP/
Playground*/
# ignore copilot agents
.github/agents/
current.diff
10 changes: 10 additions & 0 deletions BannedSymbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
T:System.ArgumentNullException; Use 'Guard' instead
P:System.DateTime.Now; Use 'IClock' instead
P:System.DateTime.UtcNow; Use 'IClock' instead
M:System.Threading.Tasks.Task.Run(System.Action); Use 'ITask' instead
M:System.Threading.Tasks.Task.WhenAll(System.Threading.Tasks.Task[]); Use 'ITask' instead
M:System.Threading.Tasks.Task.WhenAll(System.Collections.Generic.IEnumerable{System.Threading.Tasks.Task}); Use 'ITask' instead
M:System.String.IsNullOrEmpty(System.String); Use 'RoslynString.IsNullOrEmpty' instead
M:System.String.IsNullOrWhiteSpace(System.String); Use 'RoslynString.IsNullOrWhiteSpace' instead
M:System.Diagnostics.Debug.Assert(System.Boolean); Use 'RoslynDebug.Assert' instead
M:System.Diagnostics.Debug.Assert(System.Boolean,System.String); Use 'RoslynDebug.Assert' instead
38 changes: 31 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,42 @@
</ItemGroup>
<PropertyGroup>
<MicrosoftBuildVersion>17.11.48</MicrosoftBuildVersion> <!-- .NET 8.0 support -->
<MicrosoftCodeAnalysisVersion>4.12.0</MicrosoftCodeAnalysisVersion>
<NugetPackageVersion>6.14.0</NugetPackageVersion>
<MicrosoftCodeAnalysisVersion>4.13.0</MicrosoftCodeAnalysisVersion>
<!-- .NET 8.0 support -->
<NugetPackageVersion>7.0.1</NugetPackageVersion>
<!-- Test Platform, .NET Test SDK and Object Model -->
<MicrosoftNETTestSdkVersion>17.14.1</MicrosoftNETTestSdkVersion>
<MicrosoftNETTestSdkVersion>18.0.1</MicrosoftNETTestSdkVersion>
<XunitV3Version>3.0.0</XunitV3Version>
<XunitRunnerVisualstudioVersion>3.1.5</XunitRunnerVisualstudioVersion>
<MicrosoftTestingPlatformVersion>1.9.1</MicrosoftTestingPlatformVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="DotNetConfig" Version="1.2.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildVersion)" />
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildVersion)" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.10.2" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.11.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="5.0.0-1.25277.114" />
<PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<!--For test TestInstrument_NetstandardAwareAssemblyResolver_PreserveCompilationContext-->
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="$(MicrosoftNETTestSdkVersion)" />
<!--<PackageVersion Include="MSTest.TestFramework" Version="3.9.1" />-->
<!-- Microsoft Testing Platform-->
<PackageVersion Include="Microsoft.Testing.Platform" Version="$(MicrosoftTestingPlatformVersion)" />
<!--<PackageVersion Include="Microsoft.Testing.Platform.MSBuild" Version="$(MicrosoftTestingPlatformVersion)" />
<PackageVersion Include="Microsoft.Testing.Platform.MSTest" Version="$(MicrosoftTestingPlatformVersion)" />
<PackageVersion Include="Microsoft.Testing.Platform.MSTest.Extensions" Version="$(MicrosoftTestingPlatformVersion)" />-->
<PackageVersion Include="Microsoft.Testing.Extensions.HangDump" Version="$(MicrosoftTestingPlatformVersion)" />
<PackageVersion Include="Microsoft.Testing.Extensions.CrashDump" Version="$(MicrosoftTestingPlatformVersion)" />
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingPlatformVersion)" />
<PackageVersion Include="MSTest" Version="3.9.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.9.1" />
<!-- Nuget -->
<PackageVersion Include="NuGet.Frameworks" Version="$(NugetPackageVersion)" />
<PackageVersion Include="NuGet.Packaging" Version="$(NugetPackageVersion)" />
<PackageVersion Include="NuGet.Versioning" Version="$(NugetPackageVersion)" />
Expand All @@ -41,24 +56,33 @@
<!--To test issue 1104 https://github.com/coverlet-coverage/coverlet/issues/1104-->
<!-- latest Tmds.ExecFunction package uses EnvDTE V17.8.37221 -->
<PackageVersion Include="Tmds.ExecFunction" Version="0.8.0" />
<!-- <PackageVersion Include="xunit" Version="2.9.3" /> -->
<PackageVersion Include="xunit.v3" Version="$(XunitV3Version)" />
<PackageVersion Include="xunit.v3.runner.msbuild" Version="$(XunitV3Version)" />
<PackageVersion Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualstudioVersion)" />
<PackageVersion Include="System.Buffers" Version="4.6.1" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.1" />
<PackageVersion Include="System.Diagnostics.EventLog" Version="8.0.2" />
<PackageVersion Include="System.Formats.Asn1" Version="8.0.2" />
<PackageVersion Include="System.Formats.Asn1" Version="10.0.0" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.3" />
<PackageVersion Include="System.Linq.Async" Version="7.0.0" />
<PackageVersion Include="System.Memory" Version="4.6.3" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Reflection.Metadata" Version="8.0.1" />
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2" />
<PackageVersion Include="System.Security.AccessControl" Version="6.0.1" />
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="10.0.0" />
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.6" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
<!-- Could be removed - just used in Playground -->
<PackageVersion Include="Microsoft.Testing.Extensions.Telemetry" Version="$(MicrosoftTestingPlatformVersion)" />
<PackageVersion Include="MSTest.Analyzers" Version="3.9.1" />
<PackageVersion Include="StreamJsonRpc" Version="2.20.20" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.9.1" />
<PackageVersion Include="Microsoft.TestPlatform" Version="17.14.1" />
<PackageVersion Include="System.Collections.Concurrent" Version="4.3.0" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Documentation/Coverlet.MTP.Integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
### ToDo Description
28 changes: 28 additions & 0 deletions Documentation/MSBuildIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,31 @@ Here is an example of how to specify the parameter:
```shell
/p:ExcludeAssembliesWithoutSources="MissingAny"
```

## Enable Restore of instrumented assembly

The DisableManagedInstrumentationRestore property controls whether Coverlet should restore (revert) an assembly to its original state after instrumentation. By _default_, this is set to __false__, meaning:

1. Coverlet instruments (modifies) the assembly to track code coverage
1. After coverage collection, it restores the assembly back to its original state


When set to __true__:
- The assembly remains in its instrumented state
- This can help avoid file access conflicts
- Useful for testing/debugging instrumentation without restoration


Example use case:

```xml
<PropertyGroup>
<!-- Prevent Coverlet from reverting instrumentation changes -->
<DisableManagedInstrumentationRestore>true</DisableManagedInstrumentationRestore>
</PropertyGroup>
```

This setting is particularly helpful when troubleshooting instrumentation issues or when dealing with file locking problems during coverage collection.

> [!NOTE]
> Make sure instrumented binaries are not deployed into production.
Loading
Loading