I had this problem for quite some time now and i can't seem to make it work. I have created myself a runsettings file that i want to use in my pipeline to ignore some .cs and .cshtml files from the coverage results. From what i see the runsettings file is completely ignored (i am kinda sure the pipeline finds the file since if i change it's name it will fail the task with "File not found". This is the pipeline:
- task: DotNetCoreCLI@2
displayName: 'DotNetCore Test'
inputs:
command: 'test'
projects: '$(uniTestProject)'
arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code coverage" --settings coverage.runsettings'
publishTestResults: true
- task: PublishCodeCoverageResults@2
displayName: "Publish Code Coverage Report"
inputs:
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
And this is my runsettings file:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat Code Coverage">
<Configuration>
<CodeCoverage>
<Exclude>
<ModulePath>.*Storage.*</ModulePath>
<Source>.*\.cshtml</Source>
<Function>CloudViewer.Program</Function>
<Function>CloudViewer.Startup</Function>
</Exclude>
<OutputFormat>Cobertura</OutputFormat>
<OutputName>MyCustomCoverage.cobertura.xml</OutputName>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
I have already tried to specify a full path to the settings file, change it's name and run it locally with the same issues.
To exclude the .cs
file, you can use <ExcludeByFile>**/<path>/*.cs</ExcludeByFile>
in .runsettings
.
My sample for your reference:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat Code Coverage">
<Configuration>
<Format>cobertura</Format>
<ExcludeByFile>**/ClassLibrary1/Class2.cs</ExcludeByFile>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
My pipeline:
- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: 'test'
projects: '**\XUnitTestProject1.csproj'
arguments: '--configuration Release --collect:"XPlat Code Coverage" --settings XUnitTestProject1\.runsettings'
The pipeline result: