Stephen Ellis
Stephen Ellis

Reputation: 2701

How can I write a custom FXCop rule to check for conditional compilation symbols?

Can anyone advise me on how I would write an FXCop rule that checks for specific conditional compilation symbols?

If, for instance, I wanted to write an FXCop rule that checked that code has been compiled with the compilation symbol "CODE_ANALYSIS" defined, how would I go about doing that?

The only way that I can think of is to parse the .csproj file and look for . I think this way would become messy quickly as you would have to determine which of the build conditions were met for the current build. Any other suggestions appreciated.

Upvotes: 2

Views: 212

Answers (1)

George Duckett
George Duckett

Reputation: 32428

I don't believe you can, as FxCop works on compiled code and once compiled code is produced, any notion of compilation symbols is removed (as the compiler uses them to produced compiled code, but they aren't in it).

Only thing i think you could do is have some code within a CODE_ANALYSIS symbol, then check for its existence in FxCop.

Upvotes: 2

Related Questions