Thursday, February 02, 2012 4:16 PM
I want to create a custom rule with Fxcop to check if the name of the enum matchs with the name of the file.
I known that FxCop does not populate the source context for a field. So I tried to load the assembly to parse the files:
public override ProblemCollection Check(TypeNode typeNode)
Assembly targetAssembly = Assembly.Load(typeNode.DeclaringModule.ContainingAssembly.StrongName);
But I get this error:
Could not load file or assembly 'Name of my assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
Does anymore have a similar problem ?
Thursday, February 02, 2012 7:33 PM
An enum does not contain executable code, so its source context information will not be populated. Even if a PDB file is available for a given target DLL, you would not be able to locate the file in which the enum is defined.
This rule is a much better candidate for a custom StyleCop rule, where all the information you need to evaluate the rule would be reliably available.
Friday, February 03, 2012 4:50 PM
I installed StyleCop but I would like to enable it only for a specific configuration like CodeAnalysis: <RunCodeAnalysis>true</RunCodeAnalysis>But I found no similar property and when you add the line <Import Project="$(ProgramFiles)\MSBuild\StyleCop\v4.7\StyleCop.targets" /> in the csproj, StyleCop runs whatever the configuration.
Friday, February 03, 2012 6:58 PM
If you look at the contents of the StyleCop.targets file, you'll see that a property named StyleCopEnabled can be used to control whether StyleCop is executed during the build. To disable StyleCop for a given build configuration, tyr adding the following to that configuration's section in your .csproj file:
- Proposed As Answer by Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator Friday, February 10, 2012 2:26 AM
- Marked As Answer by Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator Monday, February 13, 2012 2:10 AM