Read the README that’s included as part of the XAML Toolkit CTP.
The big thing to note is that FxCop 10 Beta 2 does not currently support Silverlight. You’ll have to use FxCop 1.36 and force it to run in .NET 4 to get things to work for Silverlight. If you’re running WPF, FxCop 10 should be fine. (FxCop 10 RC & RTM wills support Silverlight)
After running FxCop, add the XAML Rule
Go to the folder where you installed the XAML Toolkit (C:\Program Files\Microsoft XAML Toolkit\) and add Microsoft.Xaml.Tools.FxCop.dll
You should see all the XAML rules added in the Rules section:
Add your Silverlight/WPF assembly and hit F5 (or Analyze). You may get a popup about finding System.Windows.dll. Have it point to C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0
WPF users can point to PresentationFramework/PresentationCore/WindowsBase in C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
You may also need to point FxCop towards System.Windows.Controls.dll which can be found in: C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Client
If everything goes smoothly you should see the rules run:
You should be able to do similar things for adding your own custom rules to FxCop as well.
One of the most common requests I had at PDC was to be able check if your WPF XAML was Silverlight friendly and vice versa. Over the next few weeks, I’ll try working on some simple rules to validate WPF/Silverlight compatibility and whether you can use the XAML between the two platforms.
Pingback: Twitted by alvinashcraft
Pingback: Tweets that mention Running FxCop rules against Silverlight or WPF XAML | Michael Shim -- Topsy.com
#1 by Thadeus on November 24, 2009 - 12:35 am
Quote
Great job !
Nevertheless i have some trouble to add your assemblies into fxcop 1.36, i have the error “Unable to load the assemblie …. or one of its dependence”
Pingback: Dew Drop – November 24, 2009 | Alvin Ashcraft's Morning Dew
#2 by Michael Shim on November 24, 2009 - 3:03 pm
Quote
Sorry about that Thadeus. We had a couple of issues but it should be all fixed now. Let me know if you still have issues.
#3 by Vikd on December 2, 2009 - 12:34 am
Quote
Thanks for posting this Michael.
I am still facing the same issue mentioned by Thadeus.
Took the latest version from http://code.msdn.microsoft.com/XAML/Release/ProjectReleases.aspx?ReleaseId=3598
#4 by Michael Sync on December 9, 2009 - 4:59 pm
Quote
Could you please support .NET 3.5 as well?
#5 by Michael Shim on December 10, 2009 - 8:54 am
Quote
Do you want to analyze 3.5 XAML or run XAML FxCop on 3.5?
We should be able to run against 3.5 XAML. I’ll try it out and see what issues pop up.
The XamlToolkit is built on System.Xaml which is a .net 4 component so we’d have to port that first (which may not be possible). Why do you want to use 3.5?
#6 by Eddie on February 16, 2010 - 10:35 am
Quote
When are the FxCop bits going to be updated for the new release candidates of VS and .NET Fx?
FxCop crashes when you point it at the new runtime.
Thanks
#7 by loyawild-online on March 7, 2010 - 9:12 pm
Quote
Aprendi mucho
#8 by Parixit Pandey on April 23, 2010 - 3:51 am
Quote
Hi Michael,
In my Machine I had Installed VS2010 Ultimate edition. even I had Installed FxCop 1.36 and Downloaded XAML Toolkit Rules. in Fxcop FxCop.exe.config file changed VS2010 Version But when I am trying to add rules in Fxcorp it giving error rules are not valid.
#9 by Michael Shim on May 3, 2010 - 9:15 pm
Quote
We’re currently working on getting a build of the Xaml Toolkit that works well against VS2010 RTM & FxCop 10. We’ll update you when we fix this.
#10 by Parixit Pandey on May 6, 2010 - 1:04 am
Quote
Hi Michael,
Now I am able to add XAML Toolkit Rules in FxCop 1.36 and even able to run the silverlight Application against it. But After running the application Not getting any error.
In case I want to write my own custom rules for XMAL what steps I have to follow. Could I get any sample code snippets.
Already I had added following code
public abstract class BaseXamlRule : BaseIntrospectionRule
{
public abstract void CheckXaml(XamlDomObject rootObjectNode,
XamlSchemaContext schemaContext,
string resourceName)
{
}
}
for XamlSchemaContext added System.XMAL Namespace but still I am not able to get XamlDomObject Class. What namespace I have to add for it ?
Please Provide sample code snippets writing XMAL rules.
Thanks,
Parixit Pandey
#11 by Michael Shim on May 7, 2010 - 9:52 am
Quote
It’s in Microsxoft.Xaml.Tools.XamlDom. Here’s a simple sample where we check to see if a property is set more than once:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xaml.Tools.XamlDom;
using System.Xaml;
using Microsoft.FxCop.Sdk;
namespace Microsoft.Xaml.Tools.FxCop.Rules
{
public class PropertiesCanOnlyBeSetOnce : BaseXamlRule
{
public PropertiesCanOnlyBeSetOnce() : base("PropertiesCanOnlyBeSetOnce") { }
public override void CheckXaml(XamlDomObject rootObjectNode, System.Xaml.XamlSchemaContext schemaContext, string resourceName) membersSet = new List ();
{
foreach (XamlDomObject objectNode in rootObjectNode.DescendantsAndSelf())
{
List
foreach (XamlDomMember memberNode in objectNode.MemberNodes)
{
if (!membersSet.Contains(memberNode.Member))
{
membersSet.Add(memberNode.Member);
}
else
{
Problems.Add(CreateProblem(GetResolution(memberNode.Member.Name), memberNode.Member.Name, memberNode, resourceName));
}
}
}
}
}
}