More on using the StyleCop TFS 2010 Build Activity– handling settings files
In a recent build I wanted a bit more control over rules used by StyleCop; in the past I have just tended to have the correct ruleset in the Program FilesStyleCop directory and be done with that. This time I wanted to make sure different rules were associated with different given solutions.
The StyleCop build activity does allow for this; there is a property to set the path to the settings file. In my build process template I set this property as below, via an assignment activity
StyleCopSettingsFile = String.Format("{0}Settings.StyleCop", localProject.Substring(0, localProject.LastIndexOf("")))
so picking up the settings.stylecop file in the solution folder, but you could use any logic you need here, or just pass the fixed path to the settings file as a build process argument.
So I placed an edited settings.stylecop in the same folder as my .SLN file under source control and ran a build. However when it ran more rules were evaluated than I had expected, in fact all the rules from the default ruleset had been used.
What I had forgotten to do was set the merge rules for StyleCop. So I opened the setting.stylecop file in the StyleCop editor (installed when you install StyleCop on the PC)
I then set the setting to not merge this ruleset with any other ones, and to always re-run all the results.
Once these changes were saved and the file checked back into TFS, StyleCop ran the rules I expected.