Skip to content

Migrate all source files to file-scoped namespaces - #17470

Merged
ViktorHofer merged 2 commits into
dotnet:mainfrom
ViktorHofer:viktorhofer/file-scoped-namespaces
Sep 7, 2026
Merged

ViktorHofer merged 2 commits into
dotnet:mainfrom
ViktorHofer:viktorhofer/file-scoped-namespaces

Conversation

@ViktorHofer

Copy link
Copy Markdown
Member

Converts all C# sources to file-scoped namespaces and enforces the style going forward.

  • Converted 1013 .cs files with a Roslyn-based transform; each file was validated by comparing the before/after token streams, and lines inside multi-line string literals were left un-dedented.
  • .editorconfig: added csharp_style_namespace_declarations = file_scoped and dotnet_diagnostic.IDE0161.severity = error to the [*.cs] section.
  • Updated the SwaggerGenerator .hb templates so regenerated Helix client code stays file-scoped.
  • Updated ToolsetInfo.cs.pp, which is generated into obj and analyzed.
  • Split the #if !NET DynamicallyAccessedMembersAttribute polyfill out of StaticReflectionConstants.cs so the remaining namespace can be file-scoped.
  • HelixJobInfo.cs: the trailing file class now lives inside the namespace; removed the redundant self-using.

Note: the C# style rules from # New line preferences down to IDE0073 currently sit under the [*.{wixproj,wxs,wxi,wxl,thm}] section and are therefore inert. That pre-existing issue is not addressed here, which is why the new rule was placed in [*.cs].

Validated with build.cmd -configuration Release -test: 0 warnings, 0 compile errors.

Enforce via IDE0161 as an error in .editorconfig.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 0d271fdd-ba34-4ec9-ae26-a77283e22196
Copilot AI lite review requested due to automatic review settings September 1, 2026 13:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Review tier: Lite
Findings: 3 Low severity

New issues introduced by this change (3)
Severity Finding
Low severity src/​Microsoft.DotNet.Build.Manifest/​AssetManifestModel.cs — The doc comment has a duplicated word ("not not"), which reads as a typo and makes the API docs…
Low severity src/​Microsoft.DotNet.XUnitConsoleRunner/​src/​common/​AssemblyResolution/​_DiagnosticMessage.cs — The constructor doc comment references DiagnosticMessage, but this type is _DiagnosticMessage.…
Low severity src/​Microsoft.DotNet.XUnitExtensions.Shared/​Attributes/​LinuxOnlyTheoryAttribute.cs — The XML doc summary says this attribute should be run only on Windows, but the type is…
What changed in this PR

This pull request migrates the Arcade repo’s C# codebase to file-scoped namespaces and adds enforcement so future changes stay consistent. It also updates code-generation inputs so regenerated sources keep the same namespace style.

Changes:

  • Converted the C# sources to file-scoped namespaces (namespace X;) across the repo.
  • Enforced the style via .editorconfig (csharp_style_namespace_declarations = file_scoped + IDE0161 as error).
  • Updated shared/codegen inputs (e.g., Helix/Swagger generator templates and shared items) to preserve file-scoped namespaces in generated output.
File Description
.editorconfig Enforces file-scoped namespaces (IDE0161 as error) going forward.
src/​Microsoft.DotNet.XUnitExtensions.Shared/​Microsoft.DotNet.XUnitExtensions.Shared.projitems Adds the DynamicallyAccessedMembersAttribute polyfill to the shared compile items.
src/​Microsoft.DotNet.XUnitExtensions.Shared/​Attributes/​LinuxOnlyTheoryAttribute.cs File-scoped namespace conversion; contains a doc-comment inconsistency flagged in review.
src/​Microsoft.DotNet.Build.Manifest/​AssetManifestModel.cs File-scoped namespace conversion; contains a doc-comment typo flagged in review.
src/​Microsoft.DotNet.XUnitConsoleRunner/​src/​common/​AssemblyResolution/​_DiagnosticMessage.cs File-scoped namespace conversion; contains a doc-comment reference issue flagged in review.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ed-namespaces

# Conflicts:
#	src/Microsoft.DotNet.Arcade.Sdk/src/CalculateAssemblyAndFileVersions.cs
#	src/Microsoft.DotNet.Arcade.Sdk/src/CompareVersions.cs
#	src/Microsoft.DotNet.Arcade.Sdk/src/GroupItemsBy.cs
#	src/Microsoft.DotNet.Build.Tasks.Installers/src/GenerateCurrentVersion.cs
#	src/Microsoft.DotNet.Build.Tasks.Installers/src/GenerateGuidFromName.cs
#	src/Microsoft.DotNet.Build.Tasks.Installers/src/GenerateMsiVersion.cs
#	src/Microsoft.DotNet.Build.Tasks.Packaging/src/GetMinimumNETStandard.cs
#	src/Microsoft.DotNet.Build.Tasks.Packaging/src/GetPackageDestination.cs
#	src/Microsoft.DotNet.Build.Tasks.Packaging/src/GetPackageVersion.cs
#	src/Microsoft.DotNet.Build.Tasks.Packaging/src/SplitDependenciesBySupport.cs
#	src/Microsoft.DotNet.Build.Tasks.VisualStudio/Vsix/GetPkgDefAssemblyDependencyGuid.cs
#	src/Microsoft.DotNet.Build.Tasks.Workloads/src/Wix/WixToolTaskBase.cs
#	src/Microsoft.DotNet.Helix/JobMonitor/Interfaces/IAzureDevOpsService.cs
#	src/Microsoft.DotNet.Helix/JobMonitor/JobMonitorRunner.cs
#	src/Microsoft.DotNet.Helix/JobMonitor/MonitorState.cs
#	src/Microsoft.DotNet.Helix/JobMonitor/Services/AzureDevOpsService.cs
#	src/Microsoft.DotNet.Helix/JobMonitor/StatusReporter.cs
#	src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/AzureDevOpsResultPublisherTests.cs
#	src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/AzureDevOpsServiceTests.cs
#	src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/Fakes/FakeAzureDevOpsService.cs
#	src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/Fakes/FakeHelixService.cs
#	src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/JobMonitorRunnerTests.cs
#	src/Microsoft.DotNet.Helix/Sdk/AzureDevOpsTask.cs
#	src/Microsoft.DotNet.Helix/Sdk/CancelHelixJob.cs
#	src/Microsoft.DotNet.Helix/Sdk/CheckAzurePipelinesTestResults.cs
#	src/Microsoft.DotNet.Helix/Sdk/CheckHelixJobStatus.cs
#	src/Microsoft.DotNet.Helix/Sdk/CreateFailedTestsForFailedWorkItems.cs
#	src/Microsoft.DotNet.Helix/Sdk/CreateMTPWorkItems.cs
#	src/Microsoft.DotNet.Helix/Sdk/CreateXUnitWorkItems.cs
#	src/Microsoft.DotNet.Helix/Sdk/GetHelixWorkItems.cs
#	src/Microsoft.DotNet.Helix/Sdk/StartAzurePipelinesTestRun.cs
#	src/Microsoft.DotNet.Helix/Sdk/StopAzurePipelinesTestRun.cs
#	src/Microsoft.DotNet.Helix/Sdk/WaitForHelixJobCompletion.cs
#	src/Microsoft.DotNet.XliffTasks/Tasks/GatherXlf.cs
Copilot AI review requested due to automatic review settings September 7, 2026 10:19
@ViktorHofer

ViktorHofer commented Sep 7, 2026 •

Copy link
Copy Markdown
Member Author

Discussed offline with a set of people who contribute to Arcade the most that this change is OK. I will manually backport it into 10 and 11 post-merge.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The change is a large-scale repo-wide refactor (1000+ files plus style enforcement), so it warrants a final human review despite only minor issues being identified here.

Review tier: Lite
Findings: 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity src/​Microsoft.DotNet.SignCheckLibrary/​Verification/​Jar/​JarError.cs — HasErrors() uses LINQ Count() on a List&lt;string&gt;, which enumerates and allocates…
Issues resolved since last review (3)
Severity Finding
Low severity src/​Microsoft.DotNet.XUnitExtensions.Shared/​Attributes/​LinuxOnlyTheoryAttribute.cs — The XML doc summary says this attribute should be run only on Windows, but the type is… View resolved comment
Low severity src/​Microsoft.DotNet.XUnitConsoleRunner/​src/​common/​AssemblyResolution/​_DiagnosticMessage.cs — The constructor doc comment references DiagnosticMessage, but this type is _DiagnosticMessage.… View resolved comment
Low severity src/​Microsoft.DotNet.Build.Manifest/​AssetManifestModel.cs — The doc comment has a duplicated word ("not not"), which reads as a typo and makes the API docs… View resolved comment

@ViktorHofer
ViktorHofer enabled auto-merge (squash) September 7, 2026 10:51
@ViktorHofer
ViktorHofer merged commit a71b81e into dotnet:main Sep 7, 2026
15 of 17 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants