title: Using .runsettings to exclude assemblies from code coverage
body: <p>When running code coverage for my solution which contains multiple projects, I noticed that Code Coverage includes also my test assemblies. </p>
  
  <p>I found an article which suggests the following template for .runsettings:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RunSettings&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;!-- Do not specify any includes. This will attempt to include all binaries --&gt;
                &lt;/Include&gt;
                &lt;Exclude&gt;
                  &lt;!-- Exclude modules that aren't to be processed, by their name / path --&gt;
                  &lt;ModulePath&gt;.*Tests\.dll$&lt;/ModulePath&gt; &lt;!-- I put it here --&gt;
                &lt;/Exclude&gt;
              &lt;/ModulePaths&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;!--
  Additional paths to search for symbol files. Symbols must be found for modules to be instrumented.
  If symbols are alongside the binaries, they are automatically picked up. Otherwise specify the here.
  Note that searching for symbols increases code coverage runtime. So keep this small and local.
  
  &lt;SymbolSearchPaths&gt;             
    &lt;Path&gt;C:\Users\User\Documents\Visual Studio 11\Projects\ProjectX\bin\Debug&lt;/Path&gt;
    &lt;Path&gt;\\mybuildshare\builds\ProjectX&lt;/Path&gt;
  &lt;/SymbolSearchPaths&gt;
  --&gt;
              &lt;Functions&gt;
                &lt;Exclude&gt;
                  &lt;Function&gt;^std::.*&lt;/Function&gt;
                  &lt;Function&gt;^ATL::.*&lt;/Function&gt;
                  &lt;Function&gt;.*::__GetTestMethodInfo.*&lt;/Function&gt;
                  &lt;Function&gt;^Microsoft::VisualStudio::CppCodeCoverageFramework::.*&lt;/Function&gt;
                  &lt;Function&gt;^Microsoft::VisualStudio::CppUnitTestFramework::.*&lt;/Function&gt;
                  &lt;Function&gt;.*::YOU_CAN_ONLY_DESIGNATE_ONE_.*&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;Sources&gt;
                &lt;Exclude&gt;
                  &lt;Source&gt;.*\\atlmfc\\.*&lt;/Source&gt;
                  &lt;Source&gt;.*\\vctools\\.*&lt;/Source&gt;
                  &lt;Source&gt;.*\\public\\sdk\\.*&lt;/Source&gt;
                  &lt;Source&gt;.*\\microsoft sdks\\.*&lt;/Source&gt;
                  &lt;Source&gt;.*\\vc\\include\\.*&lt;/Source&gt;
                &lt;/Exclude&gt;
              &lt;/Sources&gt;
              &lt;CompanyNames&gt;
                &lt;Exclude&gt;
                  &lt;CompanyName&gt;.*microsoft.*&lt;/CompanyName&gt;
                &lt;/Exclude&gt;
              &lt;/CompanyNames&gt;
              &lt;PublicKeyTokens&gt;
                &lt;Exclude&gt;
                  &lt;PublicKeyToken&gt;^B77A5C561934E089$&lt;/PublicKeyToken&gt;
                  &lt;PublicKeyToken&gt;^B03F5F7F11D50A3A$&lt;/PublicKeyToken&gt;
                  &lt;PublicKeyToken&gt;^31BF3856AD364E35$&lt;/PublicKeyToken&gt;
                  &lt;PublicKeyToken&gt;^89845DCD8080CC91$&lt;/PublicKeyToken&gt;
                  &lt;PublicKeyToken&gt;^71E9BCE111E9429C$&lt;/PublicKeyToken&gt;
                  &lt;PublicKeyToken&gt;^8F50407C4E9E73B6$&lt;/PublicKeyToken&gt;
                  &lt;PublicKeyToken&gt;^E361AF139669C375$&lt;/PublicKeyToken&gt;
                &lt;/Exclude&gt;
              &lt;/PublicKeyTokens&gt;
            &lt;/CodeCoverage&gt;
          &lt;/Configuration&gt;
        &lt;/DataCollector&gt;
      &lt;/DataCollectors&gt;
    &lt;/DataCollectionRunSettings&gt;
  &lt;/RunSettings&gt;
  </code></pre>
  
  <p>Now the problem is that as soon as I check my .runsettings file in the TEST\Test settings menu, I see Code Coverage analyzes only one of many assemblies in my solution. </p>
  
  <p>Even if I remove the line </p>
  
  <pre><code> &lt;ModulePath&gt;.*Tests\.dll$&lt;/ModulePath&gt; &lt;!-- I put it here --&gt;
  </code></pre>
  
  <p>only one assembly is analyzed. I would like to avoid adding all my assemblies to the Include list, I  just need to exclude all the test assemblies.</p>
  
  <p><strong>Why does .runsettings make code coverage see only one of the assemblies in my VS solution?</strong> </p>