From 0b8dba2c51d1d0c39afc035302b5c0c2c98201e3 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Thu, 14 May 2026 23:56:33 +1200 Subject: [PATCH] build: enable CA2007 enforcement via nested src/.editorconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move ConfigureAwait(false) enforcement (CA2007) from the legacy CodeAnalysis.ruleset to a nested src/.editorconfig. The .ruleset file no longer reliably enables CA2007 with current .NET SDKs (CA2007 is disabled by default), so the rule only fired in CI Release builds and was silently ignored locally in Rider and `dotnet build`. Using the modern dotnet_diagnostic..severity in a nested editorconfig under /src has two benefits: - it correctly activates rules that are disabled by default; - it naturally scopes the rule to library code only — tests, samples and benchmarks are unaffected, where awaiting without ConfigureAwait is fine and often more readable. Closes #2308 #skip-changelog Co-Authored-By: Claude Opus 4.7 (1M context) --- src/.editorconfig | 9 +++++++++ src/CodeAnalysis.ruleset | 5 ----- src/Directory.Build.props | 1 - 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 src/.editorconfig delete mode 100644 src/CodeAnalysis.ruleset diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 0000000000..38c5c7eeb5 --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,9 @@ +# Settings that apply only to library code under /src +# (so tests, samples, benchmarks, and integration-tests are not affected). + +[*.cs] + +# CA2007: Consider calling ConfigureAwait on the awaited task. +# Library code must always ConfigureAwait(false) to avoid deadlocks in +# callers that have a SynchronizationContext. +dotnet_diagnostic.CA2007.severity = error diff --git a/src/CodeAnalysis.ruleset b/src/CodeAnalysis.ruleset deleted file mode 100644 index 3f502775ca..0000000000 --- a/src/CodeAnalysis.ruleset +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index e3e1feb526..6817e477a5 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -32,7 +32,6 @@ false annotations - $(MSBuildThisFileDirectory)CodeAnalysis.ruleset