IT Community - Software Programming, Web Development and Technical Support

FxCop 1.36 and theGlobalSuppression.cs

This is a discussion on FxCop 1.36 and theGlobalSuppression.cs within the C# Programming forums, part of the Software Development category; FxCop 1.36 and theGlobalSuppression.cs Hi, We are using FxCop 1.36 and are trying to suppress a FxCop ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 06-17-2009, 11:10 PM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default FxCop 1.36 and theGlobalSuppression.cs

FxCop 1.36 and theGlobalSuppression.cs



Hi,


We are using FxCop 1.36 and are trying to suppress a FxCop rule for a assembly. The reason is that some Customer Names are coded Uppercase being wellkown.

Noew I followed the instruction in thread
Can FxCop 1.36 Use GlobalSuppression.cs File

1. You need to add it as a code file compiled in the project for which the suppressions apply.

So in file GlobalSuppressions.cs (selfcreated)
i simply added

using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", Scope = "assembly", Justification = "...")]

2. You need to define the compiler constant CODE_ANALYSIS for that project (if for some reason that wasn't done already).

In the Solution we added the GlobalSuppressions.cs file under 'sln-> properties -> build -> Conditional compiler symbols' we added 'CODE_ANALYSIS'

having done this we still get 11101 FXCop CA1704:Naming warnings.

What are we doing wrong?
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 06-17-2009, 11:12 PM
arjkhanna arjkhanna is offline
D-Web Incredible
 
Join Date: Mar 2007
Posts: 1,949
arjkhanna is on a distinguished road
Default Re: FxCop 1.36 and theGlobalSuppression.cs

Hi,

There are a couple of problems with this approach:

1)"assembly" is not a valid value for the Scope property. (See SuppressMessageAttribute.Scope Property (System.Diagnostics.CodeAnalysis) for the list of possible values.)


2)Although it seems reasonable to be able to exclude violations at a higher scope (e.g.: exclude all violations of a type-specific rule at the namespace level), this isn't actually possible in FxCode. Only exclusions registered against the same target as the violation target will be considered by FxCop.


You can, however, create exclusions that will work very easily using the following steps:

In the FxCop active violations list, select the violation(s) you wish to exclude.

1) Right-click your selected violation(s).

2) From the context menu, select the Copy As -> Module-level SuppressMessage.

3)Paste the suppressions into yourGlobalSuppressions.cs file.
__________________
A.Rajesh Khanna
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 06-17-2009, 11:13 PM
bluesky bluesky is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 667
bluesky is on a distinguished road
Default Re: FxCop 1.36 and theGlobalSuppression.cs

Hi,

Although it seems reasonable to be able to exclude violations at a higher scope (e.g.: exclude all violations of a type-specific rule at the namespace level), this isn't actually possible in FxCode.

Right. This is a common point of confusion. Assembly/module suppressions are no more powerful than inline suppressions. The assembly/module suppression contains information that ties it to exactly one problem instance. The only difference is where you have to put the attribute in your code (in a separate file/at the top of the file versus inline with the offending code).
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 06-17-2009, 11:14 PM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default Re: FxCop 1.36 and theGlobalSuppression.cs

Hi,

Thank you for replying.

Our problem is that a Brandname is containing to many upper case letters in its name. Has anyone got a suggestion how to exclude certain rules without unlevering FxCop to much?

We dont really want to exclude a it alá Command="S:\...\FxCopCmd.exe; /f:$(TargetPath) /c /q /searchgac /rid:-Microsoft.Naming#CA1704 since the rule would be gone for to much code.

This must be a common problem e.g. names like XML, BBC and so would produce the same problem.

As I said before the naming rule CA1704 and CA1709 produce 11101 warnings which makes either FxCop Rule or FxCop its self near unusable. I would have believed that this basic, simple and common senario would have solution?

I would really apprechiate any ideas how to solve this.
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 06-17-2009, 11:15 PM
arjkhanna arjkhanna is offline
D-Web Incredible
 
Join Date: Mar 2007
Posts: 1,949
arjkhanna is on a distinguished road
Default Re: FxCop 1.36 and theGlobalSuppression.cs

Hi all,

Have you tried adding a casing exception for this scenario to a custom dictionary?
__________________
A.Rajesh Khanna
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 06-17-2009, 11:43 PM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default Re: FxCop 1.36 and theGlobalSuppression.cs

Hi arjkhanna,

add a casing exception? must confess I don't know what that is. Could you elaborate a bit and where I should put it?
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 06-17-2009, 11:44 PM
arjkhanna arjkhanna is offline
D-Web Incredible
 
Join Date: Mar 2007
Posts: 1,949
arjkhanna is on a distinguished road
Default Re: FxCop 1.36 and theGlobalSuppression.cs

Hi,

See the section "How can I add custom words to the FxCop dictionary? How can I add project specific dictionaries?" at FxCop FAQ for an explanation of using custom dictionaries. If you open the custom dictionary installed with FxCop (usually C:\Program Files\Microsoft FxCop 1.36\CustomDictionary.xml), you will see what sorts of dictionary terms you can create. For your scenario, either a casing exception (Dictionary\Acronyms\CasingExceptions\Acronym) or a compound alternate (Dictionary\Words\Compound\Term) might do the trick. If you're not sure exactly what to add to the custom dictionary, you'll need to provide the exact terms that are giving you CA1704 and CA1709 problems in order to anyone to be able to provide more specific help here.
__________________
A.Rajesh Khanna
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 06-17-2009, 11:44 PM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default Re: FxCop 1.36 and theGlobalSuppression.cs

Thank you rajesh,

our proposed idea conceptionaly works and id like to thank you for the info here!

After playing about with the file you mentioned it turns out that the main problem is that most of the 11000 warnings come from unmarked generated code . Mostly in chunks of 7 which would be > 1000 casing entries.

But I am glad to say I could still learn more about FxCop thanks again.
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rule for generated code is ignored in FxCop 1.36 when it shouldn't be shaalini C# Programming 2 06-18-2009 08:13 PM
FxCop 1.36: 'Referenced assembly could not be found' for assemblies in GAC arjkhanna C# Programming 1 06-18-2009 03:21 AM


All times are GMT -7. The time now is 01:38 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0