<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>FxCop</title>
        <link>http://geekswithblogs.net/EltonStoneman/category/9088.aspx</link>
        <description>FxCop</description>
        <language>en-GB</language>
        <copyright>EltonStoneman</copyright>
        <managingEditor>elton.stoneman@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>CA1502:AvoidExcessiveComplexity and Lambdas</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2009/09/21/ca1502avoidexcessivecomplexity-and-lambdas.aspx</link>
            <description>&lt;p style="TEXT-ALIGN: center"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;[Source: &lt;a href="http://geekswithblogs.net/EltonStoneman"&gt;http://geekswithblogs.net/EltonStoneman&lt;/a&gt;] &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In code with lots of lambda expressions, you may trigger a false positive for the Code Analysis rule CA1502 "AvoidExcessiveComplexity". The rule calculates &lt;a href="http://www.literateprogramming.com/mccabe.pdf"&gt;cyclomatic complexity&lt;/a&gt; using the logic in &lt;strong&gt;Microsoft.FxCop.Sdk.MethodMetrics&lt;/strong&gt;, which enumerates the instruction set and increments complexity count when it finds one of a given set of opcodes. &lt;/p&gt;
&lt;p&gt;The rule was triggered by code which uses the &lt;a href="http://geekswithblogs.net/EltonStoneman/archive/2009/09/08/fluent-dal-mapping.aspx"&gt;Fluent DAL&lt;/a&gt; approach to populate a composite entity: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Entity&lt;/span&gt; GetEntity(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; entityId) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: green"&gt;//populate basic details: &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;Entity&lt;/span&gt; entity = &lt;span style="COLOR: #2b91af"&gt;Fluently&lt;/span&gt;.Load&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Entity&lt;/span&gt;&amp;gt;().With&amp;lt;&lt;span style="COLOR: #2b91af"&gt;EntityMap&lt;/span&gt;&amp;gt;() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.From&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GetEntity&lt;/span&gt;&amp;gt;(i =&amp;gt; i.Id = entityId, &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;x =&amp;gt; x.Execute()); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: green"&gt;//load child entities: &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (entity.IsKnown) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;entity.Address = &lt;span style="COLOR: #2b91af"&gt;Fluently&lt;/span&gt;.Load&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Address&lt;/span&gt;&amp;gt;().With&amp;lt;&lt;span style="COLOR: #2b91af"&gt;AddressMap&lt;/span&gt;&amp;gt;() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.From&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GetEntityAddresses&lt;/span&gt;&amp;gt;(i =&amp;gt; i.Id = entityId, &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;x =&amp;gt; x.Execute()); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;entity.Contact = &lt;span style="COLOR: #2b91af"&gt;Fluently&lt;/span&gt;.Load&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Contact&lt;/span&gt;&amp;gt;().With&amp;lt;&lt;span style="COLOR: #2b91af"&gt;ContactMap&lt;/span&gt;&amp;gt;() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.From&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GetEntityContacts&lt;/span&gt;&amp;gt;(i =&amp;gt; i.Id = entityId, &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;x =&amp;gt; x.Execute()); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;} &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;else &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: green"&gt;//more of the same&lt;/span&gt;... &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The method in question had a single if/else branch, no other conditional logic, but 7 fluent calls totalling 12 lambdas. I calculate the cyclomatic complexity to be 2, and &lt;a href="http://www.ndepend.com/"&gt;NDepend&lt;/a&gt; agrees. &lt;a href="http://msdn.microsoft.com/en-us/library/bb429476(VS.80).aspx"&gt;FxCop&lt;/a&gt; tells me the complexity is 26. &lt;/p&gt;
&lt;p&gt;I stripped this down to a much simpler sample and found the same issue: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; CCCheck2() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;Fluently&lt;/span&gt;.Load().With().From(i =&amp;gt; i.ToString(), x =&amp;gt; x.ToString()); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;Fluently&lt;/span&gt;.Load().With().From(i =&amp;gt; i.ToString(), x =&amp;gt; x.ToString()); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;Fluently&lt;/span&gt;.Load().With().From(i =&amp;gt; i.ToString(), x =&amp;gt; x.ToString()); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;}&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;- this gives a CC of 13, although it has no conditional logic at all. &lt;/p&gt;
&lt;p&gt;The answer's in the IL – the lambdas are emitted as private static classes and executed using an instance which is lazy-loaded: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;IL_000b: ldsfld class [System.Core]System.Func`2&amp;lt;int32,string&amp;gt; FxCopCC.LambdaSample::'CS$&amp;lt;&amp;gt;9__CachedAnonymousMethodDelegate6' &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;IL_0010: &lt;span style="BACKGROUND-COLOR: yellow"&gt;brtrue.s IL_0025&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;IL_0012: ldnull &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;IL_0013: ldftn string FxCopCC.LambdaSample::'&amp;lt;CCCheck&amp;gt;b__0'(int32) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;IL_0019: newobj instance void class [System.Core]System.Func`2&amp;lt;int32,string&amp;gt;::.ctor(object, &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;native int) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;IL_001e: stsfld class [System.Core]System.Func`2&amp;lt;int32,string&amp;gt; FxCopCC.LambdaSample::'CS$&amp;lt;&amp;gt;9__CachedAnonymousMethodDelegate6' &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;IL_0023: &lt;span style="BACKGROUND-COLOR: yellow"&gt;br.s IL_0025&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;br&lt;/strong&gt; and &lt;strong&gt;brtrue&lt;/strong&gt; are transfer of control statements, so every lambda expression actually causes a branch – where the IL checks to see if there's a cached instance of the delegate, or whether it needs to instantiate one – and a return. The complexity rating is correct for the IL, as 1 + 2x(number of lambdas). &lt;/p&gt;
&lt;p&gt;But cyclomatic complexity is a measure of readability, so the additional branches in the IL should be irrelevant. The short term solution is to suppress the message on methods with heavy lambda usage. A longer term option is an alternative rule which uses a different calculation. &lt;/p&gt;
&lt;p&gt;A side point is that the IL isn't aggressively optimised by the compiler – lambdas with identical code are generated as separate private classes, each with their own lazy-loading check, so to avoid that overhead lambdas which are reused can be centralised: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&amp;gt; GetInitialise() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;,&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&amp;gt;(i =&amp;gt; i.ToString()); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;}&lt;/span&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134988"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134988" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/134988.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2009/09/21/ca1502avoidexcessivecomplexity-and-lambdas.aspx</guid>
            <pubDate>Mon, 21 Sep 2009 20:47:01 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/134988.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2009/09/21/ca1502avoidexcessivecomplexity-and-lambdas.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/134988.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Configurable FxCop Rules</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2008/11/17/configurable-fxcop-rules.aspx</link>
            <description>&lt;p style="text-align: center;"&gt;&lt;span style="font-size: 10pt;"&gt;[Source: &lt;a href="http://geekswithblogs.net/EltonStoneman"&gt;http://geekswithblogs.net/EltonStoneman&lt;/a&gt;] &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;FxCop allows you to define rules as having configurable settings, and through the native UI you can override the settings and save them for each FxCop project. This is useful if you want to have a generic set of rules that can be used to enforce differing sets of standards, without having to modify the rule assemblies.  &lt;/p&gt;
&lt;p&gt;It's not well documented, but you need to implement &lt;strong&gt;IConfigurableRule&lt;/strong&gt; and provide default setting values. There's a straightforward sample on &lt;a href="http://www.yafla.com/dennisforbes/FxCop-Cyclomatic-Complexity/FxCop-Cyclomatic-Complexity.html"&gt;Dennis Forbes' blog&lt;/a&gt;, but you can move the &lt;strong&gt;IConfigurableRule&lt;/strong&gt; implementation to a base class and just have the specific setting code in the child class: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/111708_1940_Configurabl1.png" style="width: 508px; height: 319px;" /&gt; 	&lt;/p&gt;
&lt;p&gt;Bear in mind that FxCop will instantiate an instance of the rule prior to firing it during analysis, and will cache that instance for all analysis runs, so your configuration code should account for this. Key things to note: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Settings are held in two &lt;strong&gt;IDictionary&lt;/strong&gt; objects, representing the default settings and the current settings. In theory any dictionary type will do, but I had problems with using generic dictionaries, so resorted to using &lt;strong&gt;Hashtable&lt;/strong&gt;; &lt;/li&gt;
    &lt;li&gt;Add values to the default setting collection in a static constructor, then use &lt;strong&gt;ConfigurationHelper.CopyFromDefault()&lt;/strong&gt; to copy default settings to the current setting collection. This has to be in a static constructor, lazy-loading the DefaultSettings property won't work; &lt;/li&gt;
    &lt;li&gt;Use &lt;strong&gt;ConfigurationHelper.LoadSettings()&lt;/strong&gt; in your implementation of LoadSettings, to update the current dictionary with saved values from the FxCop project file; &lt;/li&gt;
    &lt;li&gt;Use &lt;strong&gt;ConfigurationHelper.SaveSettings()&lt;/strong&gt; in your SaveSettings implementation to copy the current setting values back to the FxCop project file. FxCop will only call this if the current settings differ from the defaults; &lt;/li&gt;
    &lt;li&gt;There's no event model to notify when current settings have been changed, so if you're caching downstream based on a setting value, you'll need to check the cache is valid before each call. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The need to set up defaults in a static constructor complicates the implementation of the base class. One option is to store a static collection of Hashtables in the base class, keyed by the child class type name (this is the implementation I used in &lt;a href="http://geekswithblogs.net/EltonStoneman/archive/2008/11/14/introducing-biztalkcop.aspx"&gt;BizTalkCop&lt;/a&gt;, full code samples there). &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127164"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127164" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/127164.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2008/11/17/configurable-fxcop-rules.aspx</guid>
            <pubDate>Tue, 18 Nov 2008 01:41:41 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/127164.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2008/11/17/configurable-fxcop-rules.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/127164.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Introducing: BizTalkCop</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2008/11/14/introducing-biztalkcop.aspx</link>
            <description>&lt;p style="text-align: center;"&gt;&lt;span style="font-size: 10pt;"&gt;[Source: &lt;a href="http://geekswithblogs.net/EltonStoneman"&gt;http://geekswithblogs.net/EltonStoneman&lt;/a&gt;] &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;To make good on a rash comment around the lack of standards-enforcement for BizTalk, I've put together a set of FxCop rules which allow you to run static analysis over BizTalk solutions. It covers all aspects by running rules against compiled artifact assemblies and configured BizTalk applications. It's on CodePlex here: &lt;a href="http://www.codeplex.com/BizTalkCop"&gt;BizTalkCop&lt;/a&gt;.  &lt;/p&gt;
&lt;p&gt;The first release(1.0) contains a full ruleset for validating BizTalk application artifact names, based on &lt;a href="http://www.traceofthought.net/misc/BizTalk%20Naming%20Conventions.htm"&gt;Scott Colestock's naming conventions&lt;/a&gt;. By default the rules are more strict in places, but they're configurable so you can modify them to suit your own standards. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Usage &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Currently BizTalk projects don't integrate fully with static analysis in VS 2005, so you'll need the separate FxCop UI – latest version is &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9aeaa970-f281-4fb0-aba1-d59d7ed09772&amp;amp;DisplayLang=en"&gt;FxCop 1.36&lt;/a&gt;. Once you've installed FxCop, run the BizTalkCop installer and it will add &lt;em&gt;BizTalkCop.Rules.dll&lt;/em&gt; and &lt;em&gt;BizTalkCop.Rules.chm&lt;/em&gt; to the FxCop rules folder (default: Program Files\Microsoft FxCop 1.36\Rules). Open FxCop and there are three steps to configure your BizTalk project: &lt;/p&gt;
&lt;p&gt;1. Add Targets &lt;/p&gt;
&lt;p&gt;Add the compiled BizTalk assemblies you want to check to the FxCop project. For compiled artifacts, BizTalkCop covers orchestrations, maps, schemas and pipelines so you can add any assemblies that contain these: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/111408_1034_Introducing1.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;2. Select Rules &lt;/p&gt;
&lt;p&gt;If you've used the default installation, then the BizTalkCop rule set should be listed in the Rules tab (if not you'll need to navigate to add it). Check BizTalkCop and uncheck all the others: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/111408_1034_Introducing2.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;3. Set up Application Configuration &lt;/p&gt;
&lt;p&gt;In order to validate the configured BizTalk Application, you'll need to specify the location of your management database, and the name of the Applications to check. Open the &lt;em&gt;ApplicationConfig&lt;/em&gt; rule properties (this is a dummy rule which is only there to capture BizTalk Server config), and modify the Settings to specify your server, and the Applications to run over (semi-colon separated if more than one) – you only need to do this once, and all Application rules will use these settings: &lt;/p&gt;
&lt;p&gt;&lt;img src="http://geekswithblogs.net/images/geekswithblogs_net/EltonStoneman/111408_1034_Introducing3.png" alt="" /&gt; 	&lt;/p&gt;
&lt;p&gt;When you run FxCop it'll list all the rule failures, some of which may have multiple issues (e.g. ReceiveLocationNamesShouldIndicateTransport will flag an issue for every configured location that doesn't have its transport type as a suffix). There should be no locks on targets, so you can change the artifacts and recompile, or edit application config with FxCop open, and then re-run it. &lt;/p&gt;
&lt;p&gt;Most rules are configurable, so you can modify the prefixes and suffixes to suit your standards, or ignore any rules you don't care for. Save the project as a .FxCop file and you can integrate this into your build process using the &lt;a href="http://msbuildtasks.tigris.org/"&gt;MSBuild Community Tasks.&lt;/a&gt; 	&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Development&lt;/strong&gt; 	&lt;/p&gt;
&lt;p&gt;There's potential for rules to cover a lot more than the "Naming" category. Certain of the recommendations in the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=98ecf11a-9a8e-4939-8cef-2bc5536dc792&amp;amp;DisplayLang=en"&gt;BizTalk Performance Optimization Guide&lt;/a&gt; are candidates for a "Performance" category,  and there are a few gotchas that could be avoided with warnings from a "Design" category. I'm not planning to add these for a while, but if you want to get involved let me know and I'll add you as a contributor. &lt;/p&gt;
&lt;p&gt;FxCop runs over compiled assemblies, so introducing it to BizTalk meant for a few workarounds. If you want to extend BizTalkCop by adding new rules, there are a set of base classes which will help: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;em&gt;RuleBase&lt;/em&gt; – general base class for rules using normal introspection over classes; contains methods for determining if targets are maps, schemas etc; &lt;/li&gt;
    &lt;li&gt;&lt;em&gt;ConfiguredRuleBase &lt;/em&gt;– base class for rules which have default setting values which can be overridden in the project file; &lt;/li&gt;
    &lt;li&gt;&lt;em&gt;ApplicationRuleBase&lt;/em&gt; – base class for rules analysing BizTalk Applications; wraps the Explorer OM (so not good for 64-bit) to get the current config; &lt;/li&gt;
    &lt;li&gt;&lt;em&gt;OrchestrationRuleBase&lt;/em&gt; – base class for analysing Orchestrations; typically the compiled code is too dense for analysis, so the base class exposes methods for accessing the shape and OM configuration. This is stored as XML in the compiled class, and the base class provides XPath helpers to access it. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The code for running the rule is quite straightforward, although tracking down the XML elements to check can be fiddly for orchestration rules (if you can find any schemas for the shape or OM XML, let me know and I'll modify it all to use entity classes). The source code contains a sample BizTalk project which fails all known rules, so you can add to this to check your own rules run as expected. &lt;/p&gt;
&lt;p&gt;Quite possibly the CSD have something like this in place for the VS 2008 integration coming in BizTalk Server 2009. If not, it should be a trivial job to migrate these rules to run under VS, and in any case the ability to separate them out for running in the build should be useful. &lt;/p&gt;
&lt;p&gt;I've run the rules over a few solutions and they've been accurate, but if you come across any issues, log them on CodePlex and I'll have a look. &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127018"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=127018" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/127018.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2008/11/14/introducing-biztalkcop.aspx</guid>
            <pubDate>Fri, 14 Nov 2008 16:36:06 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/127018.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2008/11/14/introducing-biztalkcop.aspx#feedback</comments>
            <slash:comments>10</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/127018.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>