title: C# Custom Code Coverage Integration in Visual Studio 2013
body: <p>I would like to enhance efficiency in our software department by providing a VS extension or add in to perform custom code coverage using VS 2013.</p>
  
  <p>The special point in that enterprise is the coverage of special code snippet actually marked by a comment like <code>//INDISPENSABLE_STUFF document comment</code> that is defined as a task token.</p>
  
  <p>I was thinking of introducing a new attribute <code>RiskAttribute</code> to qualify methods for instance but could not separate the corresponding code coverage result from the rest for reporting how much of the indispensable stuff has been covered.</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Risk Attribute
      /// &lt;/summary&gt;
          public class RiskAttribute : Attribute
          {
              private readonly string _document;
              private readonly string _comment;
  
              /// &lt;summary&gt;
              /// Constructor
              /// &lt;/summary&gt;
              /// &lt;param name="doc"&gt;&lt;/param&gt;
              /// &lt;param name="comment"&gt;&lt;/param&gt;
              public RiskAttribute(string doc, string comment)
              {
                  _document = doc;
                  _comment = comment;
              }
  
              /// &lt;summary&gt;
              /// Document
              /// &lt;/summary&gt;
              public string Document { get { return _document; } }
  
              /// &lt;summary&gt;
              /// Comment
              /// &lt;/summary&gt;
              public string Comment { get { return _comment; } }
      }
  </code></pre>
  
  <p>I turned to implement an add in but do not figure out in the 1. step how to launch the vs code coverage tool programmatically for a project using my add-in. The 2. step would be to customize the code coverage in order to parse the custom task token and return a result like <code>xy% of defined task token INDISPENSABLE_STUFF is covered</code>.</p>
  
  <p>For development, I implemented a calculator class with unit test to exercise both variations:</p>
  
  <ul>
  <li><p>The class</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Calculator
  /// &lt;/summary&gt;
  public class Calculator
  {
  
  /// &lt;summary&gt;
  /// Addition
  /// INDISPENSABLE_STUFF (DOC #2150) Test
  /// &lt;/summary&gt;
  /// &lt;param name="a"&gt;&lt;/param&gt;
  /// &lt;param name="b"&gt;&lt;/param&gt;
  /// &lt;returns&gt;&lt;/returns&gt;        
  public static decimal Add(decimal a, decimal b) { return a + b; }
  
  /// &lt;summary&gt;
  /// Substraction
  /// &lt;/summary&gt;
  /// &lt;param name="a"&gt;&lt;/param&gt;
  /// &lt;param name="b"&gt;&lt;/param&gt;
  /// &lt;returns&gt;&lt;/returns&gt;
  [RiskAttribute("DOC #2150", "Test")]
  public static decimal Sub(decimal a, decimal b) { return a - b; }
  
  }
  </code></pre></li>
  <li><p>The unit test</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Test class for Calculator
  /// &lt;/summary&gt;
  [TestClass]
  public class CalculatorTest
  {
      /// &lt;summary&gt;
      /// Tests addition
      /// &lt;/summary&gt;
      [TestMethod]
      public void Test_Sub()
      {
          decimal a = 1;
          decimal b = 2;
          Assert.AreEqual((a - b), Calculator.Sub(a, b));
      }
  }
  </code></pre></li>
  </ul>
  
  <p>So now, for the question, I already have to add-in code for the integration but miss the main content to start the customized code coverage. Does anybody know :</p>
  
  <ol>
  <li>how to adapt the code coverage to consider task token?</li>
  <li>how to start the code coverage programmatically?</li>
  </ol>
  
  <p>Sorry if these are "big" points for only "one" question.</p>
  
  <p>Thanks</p>