visual-studioroslynsolutionstatic-code-analysisroslyn-code-analysis

How do I specify a custom code analysis ruleset for multiple projects in a solution using Visual Studio 2019?


I've got a custom code analysis ruleset that I want to apply to all configurations of multiple projects in my solution but can't see how I can do it.

To be clear, I'm looking for a way (if any) of doing this in a single step rather then editing the properties of each project from the IDE.

I found this guidance so far: https://learn.microsoft.com/en-us/visualstudio/code-quality/how-to-configure-code-analysis-for-a-managed-code-project?view=vs-2019#specify-rule-sets-for-multiple-projects-in-a-solution

But it doesn't seem to be correct. In Visual Studio 2019, if I go to Analyze > Configure Code Analysis > For Solution I get a blank property page with the message:

NOTE: This property page has been deprecated and will be removed in a future product release.

Is there another way I can do this? I have lots of projects :(

Thanks.


Solution

  • I've had no answers about if there's a way to do this in Visual Studio so I've had to resort to altering .csproj files directly in a batch fashion.

    This script I found by John Robbins is excellent: https://www.wintellect.com/batch-updating-changing-visual-studio-projects-with-powershell/

    After installation, my usage was like this in case anyone is interested:

    dir -recurse *.csproj | Set-ProjectProperties -OverrideDefaultProperties -CustomConfigurationProperties @{ "CodeAnalysisRuleSet" = ".\SystemStandard.ruleset" }
    
    dir -recurse *.csproj | Set-ProjectProperties -OverrideDefaultProperties -CustomConfigurationProperties @{ "RunCodeAnalysis" = "false" }
    
    dir -recurse *.csproj | Set-ProjectProperties -OverrideDefaultProperties -CustomConfigurationProperties @{ "TreatWarningsAsErrors" = "true" }