diff --git a/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs b/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs index 5aa7c734b2..e2ab97455f 100644 --- a/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs +++ b/src/Tools/GenerateDocumentationAndConfigFiles/Program.cs @@ -252,7 +252,7 @@ void createPropsFiles() var fileContents = $@" - {disableNetAnalyzersImport}{getCompilerVisibleProperties()} + {disableNetAnalyzersImport}{getCodeAnalysisTreatWarningsAsErrors()}{getCompilerVisibleProperties()} "; var directory = Directory.CreateDirectory(propsFileDir); var fileWithPath = Path.Combine(directory.FullName, propsFileName); @@ -310,6 +310,19 @@ We rely on the additional props file '{propsFileToDisableNetAnalyzersInNuGetPack } } + string getCodeAnalysisTreatWarningsAsErrors() + { + var allRuleIds = string.Join(';', allRulesById.Keys); + return $@" + + + {allRuleIds} + $(WarningsNotAsErrors);$(CodeAnalysisRuleIds) + "; + } + string getCompilerVisibleProperties() { return analyzerPackageName switch @@ -1404,6 +1417,7 @@ static string GetCommonContents(string packageName, IOrderedEnumerable c } stringBuilder.Append(GetMSBuildContentForPropertyAndItemOptions()); + stringBuilder.Append(GetCodeAnalysisTreatWarningsAsErrorsTargetContents()); return stringBuilder.ToString(); } @@ -1594,6 +1608,21 @@ static void AddMSBuildContentForItemOptions(StringBuilder builder) } } + static string GetCodeAnalysisTreatWarningsAsErrorsTargetContents() + { + return $@" + + + + $(WarningsNotAsErrors);$(CodeAnalysisRuleIds) + + +"; + } + static string GetPackageSpecificContents(string packageName) => packageName switch { diff --git a/src/Tools/GenerateDocumentationAndConfigFiles/README.md b/src/Tools/GenerateDocumentationAndConfigFiles/README.md index b6d16c4390..6208d9c76c 100644 --- a/src/Tools/GenerateDocumentationAndConfigFiles/README.md +++ b/src/Tools/GenerateDocumentationAndConfigFiles/README.md @@ -22,4 +22,5 @@ Following are the precedence rules as per the values of these properties: 2. For CAxxxx rules: 1. If `CodeAnalysisTreatWarningsAsErrors` is set to true, enabled CA warnings are bulk escalated to errors by choosing the appropriate globalconfig file with the error severity settings. - 2. Otherwise, if `TreatWarningsAsErrors` is set to true, this property translates to `/warnaserror` command line switch and the compiler bumps all warnings, including enabled CA warnings, to errors. + 2. If `CodeAnalysisTreatWarningsAsErrors` is set to false and `TreatWarningsAsErrors` is set to true, we append all CA rule IDs to `WarningsNotAsErrors` to ensure they are not escalated to errors. Users can still bump individual rule IDs to errors by editorconfig/ruleset entry, etc. + 3. Otherwise, if `TreatWarningsAsErrors` is set to true, this property translates to `/warnaserror` command line switch and the compiler bumps all warnings, including enabled CA warnings, to errors.