title: dotnet cli - specified .runsettings file not used in code coverage run
body: <p>I have a solution containing two dotnet core 2.1 projects (c#).  </p>
  
  <ol>
  <li><p>The first is a console application</p></li>
  <li><p>The seconds is a test project with unit tests</p></li>
  </ol>
  
  <p>I generate code coverage stats about project 1 when executing tests in project 2 using this command:</p>
  
  <pre><code>dotnet test C:\tempDir\SampleApp\Tests\SampleApp.Tests.csproj 
  /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura 
  /p:CoverletOutput=C:\tempDir\Coverage\coverage 
  /p:settings=CodeCoverage.runsettings --filter Category=Unit --logger trx 
  --results-directory C:\tempDir\output
  </code></pre>
  
  <p>You can see here I specify <em>CodeCoverage.runsettings</em> as the <strong>settings</strong> parameter - <code>/p:settings=CodeCoverage.runsettings</code>.  In my run settings file, I've asked that <code>Program.cs</code> and <code>Startup.cs</code> are excluded from coverage, but they are still included in the output <em>coverage.cobertura.xml</em> file.</p>
  
  <p>Extract from output report below:</p>
  
  <pre><code>&lt;classes&gt;
      &lt;class name="SampleApp.Startup" filename="SampleApp\Startup.cs" line-rate="1" branch-rate="0" complexity="2"&gt;
        &lt;methods&gt;
          &lt;method name="ConfigureAppConfiguration" signature="(Microsoft.Extensions.Configuration.IConfigurationBuilder)" line-rate="1" branch-rate="0"&gt;
            &lt;lines&gt;
              &lt;line number="18" hits="1" branch="False" /&gt;
              &lt;line number="19" hits="1" branch="False" /&gt;
              &lt;line number="20" hits="1" branch="False" /&gt;
            &lt;/lines&gt;
          &lt;/method&gt;
          &lt;method name="ConfigureLogging" signature="(Microsoft.Extensions.Configuration.IConfiguration,Microsoft.Extensions.Logging.ILoggingBuilder)" line-rate="1" branch-rate="0"&gt;
            &lt;lines&gt;
              &lt;line number="23" hits="1" branch="False" /&gt;
              &lt;line number="24" hits="1" branch="False" /&gt;
              &lt;line number="25" hits="1" branch="False" /&gt;
              &lt;line number="26" hits="1" branch="False" /&gt;
              &lt;line number="27" hits="1" branch="False" /&gt;
            &lt;/lines&gt;
          &lt;/method&gt;
        &lt;/methods&gt;
        &lt;lines&gt;
          &lt;line number="18" hits="1" branch="False" /&gt;
          &lt;line number="19" hits="1" branch="False" /&gt;
          &lt;line number="20" hits="1" branch="False" /&gt;
          &lt;line number="23" hits="1" branch="False" /&gt;
          &lt;line number="24" hits="1" branch="False" /&gt;
          &lt;line number="25" hits="1" branch="False" /&gt;
          &lt;line number="26" hits="1" branch="False" /&gt;
          &lt;line number="27" hits="1" branch="False" /&gt;
        &lt;/lines&gt;
      &lt;/class&gt;
  &lt;/classes&gt;
  </code></pre>
  
  <p>I'm wondering what I've done wrong in my <code>runsettings</code> file? (contents of file below)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;RunSettings&gt;
      &lt;!-- Configurations for data collectors --&gt;
      &lt;DataCollectionRunSettings&gt;
          &lt;DataCollectors&gt;
              &lt;DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"&gt;
                  &lt;Configuration&gt;
                      &lt;CodeCoverage&gt;
  
                          &lt;ModulePaths&gt;
                              &lt;Include&gt;
                                  &lt;ModulePath&gt;.*dll$&lt;/ModulePath&gt;
                              &lt;/Include&gt;
                              &lt;Exclude&gt;
                                  &lt;ModulePath&gt;.*microsoft.*&lt;/ModulePath&gt;
                                  &lt;ModulePath&gt;.*moq.*&lt;/ModulePath&gt;
                                  &lt;ModulePath&gt;.*polly.*&lt;/ModulePath&gt;
                                  &lt;ModulePath&gt;.*fluentassertions.*&lt;/ModulePath&gt;
                                  &lt;ModulePath&gt;.*newtonsoft.*&lt;/ModulePath&gt;
                                  &lt;ModulePath&gt;.*SampleApp.Tests.*&lt;/ModulePath&gt;
                                  &lt;ModulePath&gt;.*\\[^\\]*DocumentManagement[^\\]*\.dll&lt;/ModulePath&gt;
                              &lt;/Exclude&gt;
                          &lt;/ModulePaths&gt;
  
                          &lt;Functions&gt;
                              &lt;Exclude&gt;
                                  &lt;Function&gt;.*\.Program\..*&lt;/Function&gt;
                                  &lt;Function&gt;.*\.Startup\..*&lt;/Function&gt;
                                  &lt;Function&gt;.*\.SomeOtherClass\..*&lt;/Function&gt;
                              &lt;/Exclude&gt;
                          &lt;/Functions&gt;
  
                          &lt;Attributes&gt;
                              &lt;Exclude&gt;
                                  &lt;Attribute&gt;^System\.Diagnostics\.DebuggerHiddenAttribute$&lt;/Attribute&gt;
                                  &lt;Attribute&gt;^System\.Diagnostics\.DebuggerNonUserCodeAttribute$&lt;/Attribute&gt;
                                  &lt;Attribute&gt;^System\.Runtime\.CompilerServices.CompilerGeneratedAttribute$&lt;/Attribute&gt;
                                  &lt;Attribute&gt;^System\.CodeDom\.Compiler.GeneratedCodeAttribute$&lt;/Attribute&gt;
                                  &lt;Attribute&gt;^System\.Diagnostics\.CodeAnalysis.ExcludeFromCodeCoverageAttribute$&lt;/Attribute&gt;
                              &lt;/Exclude&gt;
                          &lt;/Attributes&gt;
  
                          &lt;!-- We recommend you do not change the following values: --&gt;
                          &lt;UseVerifiableInstrumentation&gt;True&lt;/UseVerifiableInstrumentation&gt;
                          &lt;AllowLowIntegrityProcesses&gt;True&lt;/AllowLowIntegrityProcesses&gt;
                          &lt;CollectFromChildProcesses&gt;True&lt;/CollectFromChildProcesses&gt;
                          &lt;CollectAspDotNet&gt;False&lt;/CollectAspDotNet&gt;
  
                      &lt;/CodeCoverage&gt;
                  &lt;/Configuration&gt;
              &lt;/DataCollector&gt;
  
          &lt;/DataCollectors&gt;
      &lt;/DataCollectionRunSettings&gt;
  &lt;/RunSettings&gt;
  </code></pre>
  
  <p>Not sure why this section is still here in this output report, when I specified it being skipped in the <em>runsettings</em> file.</p>
  
  <p>NOTE:  I'm trying to avoid littering my code with the <code>[ExcludeFromCodeCoverage]</code> attribute and I don't want to have to start adding <code>/p:ExcludeByFile=Program.cs</code> or <code>/p:ExcludeByFile=Startup.cs</code> to my test command in builds, hence using the runsettings file.</p>