This repository was archived by the owner on Nov 12, 2026. It is now read-only.
Repository navigation
Conversation
Fixes dotnet#6281 Prior implementation for `CodeAnalysisTreatWarningsAsErrors` passed `/warnaserror+:CAxxxx` to the command line for each CA rule ID. This led to couple of issues: 1. All disabled by default CA warnings seem to get enabled as errors 2. Editorconfig/globalconfig based configuration of the enabled CA rules stops working. The new implementation updates our globalconfig tooling to generate parallel globalconfigs with `_warnaserror` suffix, such that rules which would have had effective warning severity are set to error severity in the new globalconfig files. The targets/props that picks the appropriate globalconfig based on the `AnalysisLevel` property now chooses the file with `_warnaserror` suffix if user has enabled code analysis warnings to be treated as errors. Another couple of notes: 1. Given that the buggy implementation of `CodeAnalysisTreatWarningsAsErrors` has already shipped in .NET7 and prior SDKs, we use a separate property `EffectiveCodeAnalysisTreatWarningsAsErrors`, so users using the newer NuGet package, but older .NET SDK can still get this functionality. Users that move to the newer .NET8 preview SDK with this fix can use `CodeAnalysisTreatWarningsAsErrors` itself. 2. I have adjusted the tooling to generate the config files into buildtransitive folder instead of build folder. This is needed as a follow-up to dotnet#6325 for globalconfig files to be correctly mapped. 3. I have also renamed all the tooling generated globalconfig files to have .globalconfig extension instead of .editorconfig extension, as that was misleading. I have verified that `CodeAnalysisTreatWarningsAsErrors` works fine with the locally built package when `EffectiveCodeAnalysisTreatWarningsAsErrors` is set to true. If I manually edit the targets/props shipped inside .NET7 SDK to delete all the prior shipped `CodeAnalysisTreatWarningsAsErrors` logic, then setting `CodeAnalysisTreatWarningsAsErrors` also works fine.
Author
|
@jmarolf @Youssef1313 for review |
mavasani
commented
Jan 12, 2023
| if (Path.GetExtension(globalconfig) == ".globalconfig") | ||
| { | ||
| result.AppendLine(FileElement(Path.Combine(globalAnalyzerConfigsDir, editorconfig), $"build\\config")); | ||
| result.AppendLine(FileElement(Path.Combine(globalAnalyzerConfigsDir, globalconfig), $"buildtransitive\\config")); |
Author
There was a problem hiding this comment.
@Youssef1313 This is the fix to generate config files in buildtransitive folder next to props/targets
mavasani
commented
Jan 12, 2023
mavasani
added a commit
to dotnet/sdk
that referenced
this pull request
Jan 12, 2023
React to package structure updates in dotnet/roslyn-analyzers#6325 and dotnet/roslyn-analyzers#6427 to generate props/targets/config files in `buildtransitive` folder
Youssef1313
approved these changes
Jan 12, 2023
mavasani
force-pushed
the
CodeAnalysisTreatWarningsAsErrors_GlobalConfigs
branch
from
January 12, 2023 12:33
479771d to
1d7244a
Compare
Author
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6427 +/- ##
=======================================
Coverage 96.14% 96.15%
=======================================
Files 1365 1365
Lines 317494 317494
Branches 10269 10269
=======================================
+ Hits 305269 305271 +2
+ Misses 9791 9787 -4
- Partials 2434 2436 +2 |
Author
|
Thank you for the review @Youssef1313 |
mavasani
added a commit
to dotnet/sdk
that referenced
this pull request
Jan 16, 2023
React to package structure updates in dotnet/roslyn-analyzers#6325 and dotnet/roslyn-analyzers#6427 to generate props/targets/config files in `buildtransitive` folder
dotnet-maestro Bot
added a commit
to dotnet/sdk
that referenced
this pull request
Jan 17, 2023
[main] Update dependencies from dotnet/roslyn-analyzers - Update GenerateLayout.targets React to package structure updates in dotnet/roslyn-analyzers#6325 and dotnet/roslyn-analyzers#6427 to generate props/targets/config files in `buildtransitive` folder - Update GenerateLayout.targets
mavasani
added a commit
to mavasani/roslyn-analyzers
that referenced
this pull request
Jan 20, 2023
Fixes [AB#1726853](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1726853) dotnet#6427 re-implemented CodeAnalysisTreatWarningsAsErrors support using global config files instead of appending CA rule IDs to WarningsAsErrors and WarningsNotAsErrors properties. However, this new implementation only works as expected for `CodeAnalysisTreatWarningsAsErrors = true` case, but doesn't prevent escalating CA warnings to errors for `CodeAnalysisTreatWarningsAsErrors = false` and `TreatWarningsAsErrors = true` case. I am restoring the WarningsNotAsErrors logic deleted from dotnet#6427 to fix this case. I am also planning to file a separate tracking issue in Roslyn to see if we can implement this whole CodeAnalysisTreatWarningsAsErrors functionality in the compiler layer itself, instead of the current hybrid implementations in this repo, which seems to be quite a bit fragile.
mavasani
added a commit
to mavasani/roslyn-analyzers
that referenced
this pull request
Jan 20, 2023
Fixes [AB#1726853](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1726853) dotnet#6427 re-implemented CodeAnalysisTreatWarningsAsErrors support using global config files instead of appending CA rule IDs to WarningsAsErrors and WarningsNotAsErrors properties. However, this new implementation only works as expected for `CodeAnalysisTreatWarningsAsErrors = true` case, but doesn't prevent escalating CA warnings to errors for `CodeAnalysisTreatWarningsAsErrors = false` and `TreatWarningsAsErrors = true` case. I am restoring the WarningsNotAsErrors logic deleted from dotnet#6427 to fix this case. I am also planning to file a separate tracking issue in Roslyn to see if we can implement this whole CodeAnalysisTreatWarningsAsErrors functionality in the compiler layer itself, instead of the current hybrid implementations in this repo, which seems to be quite a bit fragile.
ViktorHofer
pushed a commit
to dotnet/sdk
that referenced
this pull request
Aug 15, 2025
Fixes [AB#1726853](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1726853) dotnet/roslyn-analyzers#6427 re-implemented CodeAnalysisTreatWarningsAsErrors support using global config files instead of appending CA rule IDs to WarningsAsErrors and WarningsNotAsErrors properties. However, this new implementation only works as expected for `CodeAnalysisTreatWarningsAsErrors = true` case, but doesn't prevent escalating CA warnings to errors for `CodeAnalysisTreatWarningsAsErrors = false` and `TreatWarningsAsErrors = true` case. I am restoring the WarningsNotAsErrors logic deleted from dotnet/roslyn-analyzers#6427 to fix this case. I am also planning to file a separate tracking issue in Roslyn to see if we can implement this whole CodeAnalysisTreatWarningsAsErrors functionality in the compiler layer itself, instead of the current hybrid implementations in this repo, which seems to be quite a bit fragile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6281
Prior implementation for
CodeAnalysisTreatWarningsAsErrorspassed/warnaserror+:CAxxxxto the compiler command line for each CA rule ID. This led to couple of issues:The new implementation updates our globalconfig tooling to generate parallel globalconfigs with
_warnaserrorsuffix, such that rules which would have had effective warning severity are set to error severity in the new globalconfig files. The targets/props that picks the appropriate globalconfig based on theAnalysisLevelproperty now chooses the file with_warnaserrorsuffix if user has enabled code analysis warnings to be treated as errors.Another couple of notes:
CodeAnalysisTreatWarningsAsErrorshas already shipped in .NET7 and prior SDKs, we use a separate propertyEffectiveCodeAnalysisTreatWarningsAsErrors, so users using the newer NuGet package, but older .NET SDK can still get this functionality. Users that move to the newer .NET8 preview SDK with this fix can useCodeAnalysisTreatWarningsAsErrorsitself.buildTransitivedirectoryΒ #6325 for globalconfig files to be correctly mapped.I have verified that
CodeAnalysisTreatWarningsAsErrorsworks fine with the locally built package whenEffectiveCodeAnalysisTreatWarningsAsErrorsis set to true. If I manually edit the targets/props shipped inside .NET7 SDK to delete all the prior shippedCodeAnalysisTreatWarningsAsErrorslogic, then settingCodeAnalysisTreatWarningsAsErrorsalso works fine.