سؤال

We are having a solution containing several projects (some productive-code projects, some test-projects containing our unit tests).

Basically, we want to have the same code analysis rules enabled for all projects, including the test projects, to keep them aligned. Nevertheless, i just wanted to disable two rules of the code Analysis (CA1707 and CA1702) for our testprojects. I could create a new .ruleset file, containing the very same rules as my master-ruleset does, but i do not want to duplicate these settings. Let's assume, we decide to enable a rule in our master ruleset in the future, i want it to automatically be enabled in my testproject-ruleset.

Is it the right way to define my master-ruleset containing all solution wide common rules (so CA 1707 and CA 1702 would be excluded) and setup a merged ruleset for my productive code, using the master-ruleset as base and additionally include the other two?

Or is there a way to define my master-ruleset to contain all rules and then exclude them explicit from the ruleset?

هل كانت مفيدة؟

المحلول

Yes, this is possible. Rulesets can "import" other rulesets, then override settings for single or multiple rules. This can be configured from the Visual Studio UI using the steps described under "To create a custom rule set from multiple existing rule sets" at http://msdn.microsoft.com/en-us/library/dd264974.aspx (even if you only want to import a single ruleset). Alternately, this can be done by manually editing the ruleset file XML to add references to the imported ruleset(s). e.g.:

<Include Path="SomeOtherRuleset.ruleset" Action="Default" />

For an example of this, see the ExtendedCorrectnessRules.ruleset file that was installed with Visual Studio.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top