This project is read-only.

How to Write a Plug-in For the Best Practices Analyzer

Version: Beta 1
Date: September 11, 2006


The best practices analyzer (BPA) code base supports a plug-in architecture that allows users to add a new analyzer as a plug-in using the existing broader framework for similar BPA tools. In this document we will walk you through the creation of a new ASP.NET analyzer plug-in.

Note: To create a plug-in for the Best Practices Analyzer (BPA), you must have a version of Visual Studio 2005 installed on your machine. If you do not have Visual Studio 2005, you can download a free version of Visual C# Express from Microsoft.

How to add a new analyzer plug-in

Add a new analyzer project
First step creating a new project that references the correct assemblies from the BPA engine. You should create a new project in the language of your choice (we will be using C# in all example code in this document.) Once the project has been created, you'll need to add reference to the following framework projects that we will depend on:

Add a new analyzer class
Add a new class for your analyzer (YourNewAnalyzer) by inheriting from the Analyzer class in
Microsoft.VSPowerToys.BestPracticesAnalyzer.UserInterface namespace:

class MyAnalyzer : Microsoft.VSPowerToys.BestPracticesAnalyzer.UserInterface.Analyzer
Setup your new analyzer properties
In the constructor of your new Analyzer class set the configurationFileName (this XML file defines the rules and other parameters specific to your new analyzer.) The name of the file can be anything, just remember what it is. Specify the name of your tool by setting the following field names:

ToolShortName = YourNewAnalyzerLoc.ToolFullName;
ToolLongNameStart = YourNewAnalyzerLoc.ToolLongNameStart;
ToolLongNameEnd = YourNewAnalyzerLoc.ToolLongNameEnd;
LabelWDesc = YourNewAnalyzerLoc.LabelWDesc;
ButtonStartScan = YourNewAnalyzerLoc.ButtonStartScan;

where "YourNewAnalyzerLoc" is a resource file where you will be storing the strings necessary for your plug-in.
Methods that need to be overridden.
Fill in the run time options for the scan by setting the scanInfo.Options properties. For example:

protected override void GetBPAScanInfo(BPAScanInfo scanInfo, string[] argsIn)
foreach (string option in scanOptions.RestrictionOptions)

for (int s = 0; s < scanOptions.Substitutions.Count; s++)
scanInfo.Options.Substitutions.Add(scanOptions.Substitutions.GetKey(s), scanOptions.Substitutions.GetByIndex(s));

public override void InitializeAnalyzerCustomizations()
customizations = new BPACustomizations("BPA", new BPACustomizations.GetBPAScanInfoCallback(GetBPAScanInfo));
customizations.RegistrySettings = new BPARegistrySettings();
scanOptions = new ScanOptions(this);

Then, implement any additional configuration necessary:

protected override void ProcessConfiguration(Document doc)
if (scanOptions != null && mainGUI != null)

public override string ToString()
return LongNameStart + " " + LongNameEnd;

Last edited Oct 16, 2006 at 10:02 PM by joemorel, version 4


No comments yet.