Questions tagged [fxcop]

Microsoft's free static analysis tool for analyzing .NET managed code assemblies.

FxCop can be used to find coding design issues quickly and early, comes with switchable rulesets, and supports the creation of custom rules.

Available with certain versions of Visual Studio and as part of the Windows 7 SDK, available here.

749 questions
5
votes
1 answer

FxCop: custom rule for checking assembly info values

Is there a reasonably simple way to get FxCop to check that all my assemblies declare a particular attribute value? I want to make sure everyone has changed the default you get on creating a project: [assembly: AssemblyCompany("Microsoft")] //…
Julia Hayward
  • 1,987
  • 1
  • 14
  • 16
5
votes
5 answers

Any alternatives for code analysis in .net apart from FxCop?

I was wondering if there are any alternatives for code analysis. I suppose one can create a code analyser from scratch though this is a tedious work and I am not sure it worths it after all. Is there other, non .net specific, analysers? Thanks, Sun
Sunscreen
  • 3,452
  • 8
  • 34
  • 40
5
votes
2 answers

VS2010 code analysis. Suppress message CA1051:DoNotDeclareVisibleInstanceFields for all class members

I have a class like this one: public class Foo { public readonly int A = 1; public readonly int B = 2; } When I run VS2010 built in Code Analysis tool, I get 2 identical warnings: that 'field '...' is visible outside of its declaring type,…
5
votes
3 answers

Should I always specify which IFormatProvider to use?

I tried running FxCop on a few assemblies of our product, and I get lots and lots of matches of the "Specify IFormatProvider" rule. As it happens, some of those are legitimate, but it also matches code like this: Logger.DebugFormat("Appending file…
Simon Lindgren
  • 500
  • 1
  • 6
  • 14
5
votes
2 answers

CA1709 - Should we ignore this and use Db or DB?

I know it sounds silly, but in regards to CA1709, should we ignore this error and just do what Microsoft did (which is use Db as the acronym for Database)? Just wondering what people out there are doing. To me, it seems silly to use DB when…
myermian
  • 31,823
  • 24
  • 123
  • 215
5
votes
3 answers

FxCop: CA1033 - Microsoft's implementation of a ReadOnlyCollection violates this?

If you look at the code for a read-only collection it does not have an "Add" method, but instead defines the ICollection.Add(T Value) method (explicit interface implementation). When I did something similar with my ReadOnlyDictionary class, FxCop…
myermian
  • 31,823
  • 24
  • 123
  • 215
5
votes
2 answers

Can you turn off conditional compilation symbols from msbuild.exe command line?

We have CODE_ANALYSIS defined in our C# components so that FxCop analyzes them when we build them on our development boxes. I would like to have FxCop turned off when it runs through our build system. The build system is obviously using the…
blachniet
  • 4,323
  • 5
  • 33
  • 34
5
votes
1 answer

Custom Rule in FxCop to only apply to methods called by particular type's method

I want to create an FxRule that applies a method, only if the method gets called from a specific class. NOTE: I don't want to just apply a rule to a method of a particular class, i want to be able to handle methods calling other methods calling…
George Duckett
  • 31,770
  • 9
  • 95
  • 162
5
votes
2 answers

Making TeamCity FxCop build step cause a build fail if a rule is violated

I have two build steps in my build configuration: Visual Studio (sln) build runner, followed by an FxCop build runner. I'm using TeamCity 6.0.1 and FxCop 10.0. Out of the box, the FxCop runner in TeamCity seems to only report on rule violations, and…
Llyle
  • 5,980
  • 6
  • 39
  • 56
5
votes
0 answers

Is there a nice way to edit code analysis rulesets outside of Visual Studio

As a former Visual Studio user, I'm used to being able to edit my code analysis (e.g. for FxCop and StyleCop) in the IDE. The built in editor makes it really easy. I'm now using VS Code and trying to do the same thing. As far as I can tell, there…
Tom Wright
  • 11,278
  • 15
  • 74
  • 148
5
votes
4 answers

Should we use FxCop on UnitTest assemblies?

We use FxCop for all of our projects. For our UnitTests I am not sure it is worth it. We end up with many suppresses: [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification =…
Peter
  • 3,563
  • 5
  • 30
  • 43
5
votes
1 answer

FxCop Abstract types should not have constructors when no new

I have an issue with FxCop and the warning: Abstract types should not have constructors. This is being displayed for a number of abstract classes (possibly all, I haven't checked). When I look most of them have no new method so I assume it's the…
themaninthesuitcase
  • 4,771
  • 5
  • 25
  • 34
5
votes
5 answers

Link to Microsoft coding standard/ best practices documentation?

can anyone post the link to the Microsoft development best practices and guidelines? i have searched high and low for this and cant seem to find the resource i am looking for. In particular i am lookign for the development guidelines Microsoft…
kacalapy
  • 9,806
  • 20
  • 74
  • 119
5
votes
3 answers

Sonarqube 5.4 custom rule for C#

I'm using SonarQube 5.4 to analyse my own C# code, the analysis works as I expected. Now I have written some custom rules, one using StyleCop and another using FxCop to run on my code, but I don't find how to import theese custom rule in…
grandeale83
  • 141
  • 2
  • 14
5
votes
3 answers

How to fail TFS build based on FXCop warning

We are currently using TFS 2008 for source control and continuous integration. We use FXCop to check for checking performance and security warnings. The Architect or senior developer runs FX Cop at the end of a sprint or before a delivery. We would…
Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252