Microsoft XAML Toolkit CTP – July 2010: FxCop Integration
This post describes the FxCop Integration feature of the XAML Toolkit CTP – July 2010, announced here and downloadable here. It borrows heavily from Mike Shim’s earlier post on XAML FxCop.
The tool kit’s integration with FxCop has been tested against FxCop version 1.36 but that version of FxCop is a .Net 3 application and must be configured to run in .Net 4 in order to use the XAML FxCop rules.
To configure FxCop 1.36 to run on .Net 4.0 you need to add the following XML to your FxCop.exe.config file:
1: <startup>
2: <supportedRuntime version="v4.0.30319"/>
3: </startup>
Alternately, the toolkit provides a replacement FxCop.exe.config.
Using FxCop
Start FxCop and add the XAML rules.
Go to the folder where you installed the XAML Toolkit (typically C:\Program Files\Microsoft XAML Toolkit\) and add Microsoft.Xaml.Tools.FxCop.dll
You should see all the XAML rules added to the Rules section.
Go back to “Project” –> “Add Targets” and add your Silverlight or WPF or Workflow assemblies that have XAML resources.
Prompts for Dependent Assemblies
Silverlight - You should no longer get a popup asking you to find System.Windows.dll when you run the rules (with “Analyze”). When loading Silverlight targets you will be still be prompted to supply the path to the correct mscorlib.dll for your version of Silverlight. The path to the Silverlight mscorlib.dll should be in the reference assemblies of the Silverlight Visual Studio project used to build the target assembly. Typically found at: C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight.
WPF – You will get prompted for the path to PresentationFramework.dll when Analyzing WPF XAML assemblies. Again, the best answer is the path found in the project file of solution that created the assembly, typically found at: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0.
64bit – Remember, on 64 bit machines the above paths are modified to: C:\Program Files (x86) \Reference Assemblies.
Analyze
If everything goes smoothly, you can now press “Analyze” and you see the rules run. And there will be some output like:
You should be able to do similar things for adding your own custom rules to FxCop as well.