I have an integration test project with the following config in the project's .csproj file:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<RunSettingsFilePath>$(MSBuildProjectDirectory)\project.runsettings</RunSettingsFilePath>
</PropertyGroup>
In the same directory as the .csproj file, I have the file project.runsettings that contains:
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Exclude>
<ModulePath>microsoft.azure.webjobs.*</ModulePath>
</Exclude>
</ModulePaths>
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
When I run this test locally, and I inspect the generated coverage report, the excluded modules are properly excluded; they don't figure in the report. But when running the same test in a Devops pipeline, I see the excluded modules included:
How to exclude them in the pipeline build? I followed the docs but I'm not seeing what I would expect. Code coverage of the excluded modules is artificially lowering the total percentage of code coverage.

I got it working in the end. I was missing the
coverlet.msbuildNuGet package in my project. It turns out bothcoverlet.collector(which I had installed) andcoverlet.msbuildare required.The reference to the
project.runsettingsfile was correct. Its content needed to be slightly updated:And also, I needed to adjust my Azure pipelines yaml file to contain:
In your use case, it's likely your conditions will be different.
This was enough to get it working and generating a code coverage report. Hope this helps someone in the future!