Repository navigation
[net10.0][XSG] Suppress CA2252 on generated AllowImplicitXmlnsDeclaration attribute - #40213
Conversation
Co-authored-by: Rui Marinho <me@ruimarinho.net>
…030.4 (#32309) On relative base path root Microsoft.AspNetCore.Authentication.Facebook , Microsoft.AspNetCore.Authentication.Google , Microsoft.AspNetCore.Authentication.MicrosoftAccount , Microsoft.AspNetCore.Authorization , Microsoft.AspNetCore.Components , Microsoft.AspNetCore.Components.Analyzers , Microsoft.AspNetCore.Components.Forms , Microsoft.AspNetCore.Components.Web , Microsoft.AspNetCore.Components.WebAssembly , Microsoft.AspNetCore.Components.WebAssembly.Server , Microsoft.AspNetCore.Components.WebView , Microsoft.AspNetCore.Metadata , Microsoft.Extensions.Configuration , Microsoft.Extensions.Configuration.Abstractions , Microsoft.Extensions.Configuration.Json , Microsoft.Extensions.DependencyInjection , Microsoft.Extensions.DependencyInjection.Abstractions , Microsoft.Extensions.FileProviders.Abstractions , Microsoft.Extensions.Hosting.Abstractions , Microsoft.Extensions.Logging , Microsoft.Extensions.Logging.Abstractions , Microsoft.Extensions.Logging.Console , Microsoft.Extensions.Logging.Debug , Microsoft.Extensions.Primitives , Microsoft.JSInterop , Microsoft.NETCore.App.Ref From Version 10.0.0 -> To Version 10.0.0 Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.XUnitExtensions From Version 10.0.0-beta.25523.113 -> To Version 10.0.0-beta.25530.104 Microsoft.NET.Sdk From Version 10.0.100-rtm.25523.113 -> To Version 10.0.100-rtm.25530.104 Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
…031.2 (#32328) On relative base path root Microsoft.AspNetCore.Authentication.Facebook , Microsoft.AspNetCore.Authentication.Google , Microsoft.AspNetCore.Authentication.MicrosoftAccount , Microsoft.AspNetCore.Authorization , Microsoft.AspNetCore.Components , Microsoft.AspNetCore.Components.Analyzers , Microsoft.AspNetCore.Components.Forms , Microsoft.AspNetCore.Components.Web , Microsoft.AspNetCore.Components.WebAssembly , Microsoft.AspNetCore.Components.WebAssembly.Server , Microsoft.AspNetCore.Components.WebView , Microsoft.AspNetCore.Metadata , Microsoft.Extensions.Configuration , Microsoft.Extensions.Configuration.Abstractions , Microsoft.Extensions.Configuration.Json , Microsoft.Extensions.DependencyInjection , Microsoft.Extensions.DependencyInjection.Abstractions , Microsoft.Extensions.FileProviders.Abstractions , Microsoft.Extensions.Hosting.Abstractions , Microsoft.Extensions.Logging , Microsoft.Extensions.Logging.Abstractions , Microsoft.Extensions.Logging.Console , Microsoft.Extensions.Logging.Debug , Microsoft.Extensions.Primitives , Microsoft.JSInterop , Microsoft.NETCore.App.Ref From Version 10.0.0 -> To Version 10.0.0 Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.XUnitExtensions From Version 10.0.0-beta.25530.104 -> To Version 10.0.0-beta.25531.102 Microsoft.NET.Sdk From Version 10.0.100-rtm.25530.104 -> To Version 10.0.100-rtm.25531.102 Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
* Update dependencies from https://github.com/dotnet/macios build 20251030.6 On relative base path root Microsoft.iOS.Sdk.net10.0_26.0 , Microsoft.MacCatalyst.Sdk.net10.0_26.0 , Microsoft.macOS.Sdk.net10.0_26.0 , Microsoft.tvOS.Sdk.net10.0_26.0 From Version 26.0.11017 -> To Version 26.0.11018 * Update dependencies from https://github.com/dotnet/macios build 20251031.4 On relative base path root Microsoft.iOS.Sdk.net10.0_26.0 , Microsoft.MacCatalyst.Sdk.net10.0_26.0 , Microsoft.macOS.Sdk.net10.0_26.0 , Microsoft.tvOS.Sdk.net10.0_26.0 From Version 26.0.11017 -> To Version 26.0.11019 * Update dependencies from https://github.com/dotnet/macios build 20251103.2 On relative base path root Microsoft.iOS.Sdk.net10.0_26.0 , Microsoft.MacCatalyst.Sdk.net10.0_26.0 , Microsoft.macOS.Sdk.net10.0_26.0 , Microsoft.tvOS.Sdk.net10.0_26.0 From Version 26.0.11017 -> To Version 26.0.11020 --------- Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
# Conflicts: # NuGet.config
### Description of Change Update net10.0 with latest from main
# Conflicts: # NuGet.config # global.json
### Description of Change Bring latest changes from main to net10.0 branch
* Update dependencies from https://github.com/dotnet/dotnet build 20251203.3 On relative base path root Microsoft.AspNetCore.Authentication.Facebook , Microsoft.AspNetCore.Authentication.Google , Microsoft.AspNetCore.Authentication.MicrosoftAccount , Microsoft.AspNetCore.Authorization , Microsoft.AspNetCore.Components , Microsoft.AspNetCore.Components.Analyzers , Microsoft.AspNetCore.Components.Forms , Microsoft.AspNetCore.Components.Web , Microsoft.AspNetCore.Components.WebAssembly , Microsoft.AspNetCore.Components.WebAssembly.Server , Microsoft.AspNetCore.Components.WebView , Microsoft.AspNetCore.Metadata , Microsoft.Extensions.Configuration , Microsoft.Extensions.Configuration.Abstractions , Microsoft.Extensions.Configuration.Json , Microsoft.Extensions.DependencyInjection , Microsoft.Extensions.DependencyInjection.Abstractions , Microsoft.Extensions.FileProviders.Abstractions , Microsoft.Extensions.Hosting.Abstractions , Microsoft.Extensions.Logging , Microsoft.Extensions.Logging.Abstractions , Microsoft.Extensions.Logging.Console , Microsoft.Extensions.Logging.Debug , Microsoft.Extensions.Primitives , Microsoft.JSInterop , Microsoft.NETCore.App.Ref From Version 10.0.1 -> To Version 10.0.2 Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.XUnitExtensions From Version 10.0.0-beta.25562.108 -> To Version 10.0.0-beta.25603.103 Microsoft.NET.Sdk From Version 10.0.101-servicing.25562.108 -> To Version 10.0.102-servicing.25603.103 * Fix global * Update dependencies from https://github.com/dotnet/dotnet build 20251204.5 On relative base path root Microsoft.AspNetCore.Authentication.Facebook , Microsoft.AspNetCore.Authentication.Google , Microsoft.AspNetCore.Authentication.MicrosoftAccount , Microsoft.AspNetCore.Authorization , Microsoft.AspNetCore.Components , Microsoft.AspNetCore.Components.Analyzers , Microsoft.AspNetCore.Components.Forms , Microsoft.AspNetCore.Components.Web , Microsoft.AspNetCore.Components.WebAssembly , Microsoft.AspNetCore.Components.WebAssembly.Server , Microsoft.AspNetCore.Components.WebView , Microsoft.AspNetCore.Metadata , Microsoft.Extensions.Configuration , Microsoft.Extensions.Configuration.Abstractions , Microsoft.Extensions.Configuration.Json , Microsoft.Extensions.DependencyInjection , Microsoft.Extensions.DependencyInjection.Abstractions , Microsoft.Extensions.FileProviders.Abstractions , Microsoft.Extensions.Hosting.Abstractions , Microsoft.Extensions.Logging , Microsoft.Extensions.Logging.Abstractions , Microsoft.Extensions.Logging.Console , Microsoft.Extensions.Logging.Debug , Microsoft.Extensions.Primitives , Microsoft.JSInterop , Microsoft.NETCore.App.Ref From Version 10.0.1 -> To Version 10.0.2 Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.XUnitExtensions From Version 10.0.0-beta.25562.108 -> To Version 10.0.0-beta.25604.105 Microsoft.NET.Sdk From Version 10.0.101-servicing.25562.108 -> To Version 10.0.102-servicing.25604.105 * Update nuget.config with 9.0.12 * REvert changes for internal --------- Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com> Co-authored-by: Rui Marinho <me@ruimarinho.net>
* [ci] Update iOS and Android workloads * Update feeds * Update MacCatalyst, macOS, iOS, and tvOS SDK versions * Update versions again * Add feed * Aspnetcore 9.0.12 feed * [tests] Suppress Xcode version check
* Add 8.0.23 * Try fix xcode select * [ci] Update arcade * Try specific version * Try script * Try fix MicrosoftNETSdkPackageVersion
### Description of Change Bring latest changes from main to net10.0
> [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! Merges main branch changes into net10.0.
### Description of Change This pull request updates several dependency versions and package sources to ensure the project uses the latest stable releases of .NET, macOS/iOS/tvOS/MacCatalyst SDKs, and related libraries. The changes primarily focus on bumping version numbers and updating SHA references for consistency and security, as well as modifying NuGet package sources to match the new dependencies. Dependency and SDK version updates: * Updated .NET SDK and related package versions from `10.0.102-servicing.25604.105` to `10.0.103-servicing.26057.111` in `eng/Version.Details.xml` and `eng/Versions.props`, including `Microsoft.NET.Sdk`, `Microsoft.NETCore.App.Ref`, and various `Microsoft.Extensions.*` libraries. [[1]](diffhunk://#diff-fb62e94a1d6f29f863e3d0a22aa38269f6cd1d7f03b109dc06e2cbf2548b86d3L3-R9) [[2]](diffhunk://#diff-1ea18ff65faa2ae6fed570b83747086d0317f5e4bc325064f6c14319a9c4ff67L33-R54) * Updated previous .NET 9 stable release versions for `Microsoft.MacCatalyst.Sdk`, `Microsoft.macOS.Sdk`, `Microsoft.iOS.Sdk`, and `Microsoft.tvOS.Sdk` from `26.0.9779` to `26.0.9784` in both `eng/Version.Details.xml` and `eng/Versions.props`. [[1]](diffhunk://#diff-fb62e94a1d6f29f863e3d0a22aa38269f6cd1d7f03b109dc06e2cbf2548b86d3L38-R159) [[2]](diffhunk://#diff-1ea18ff65faa2ae6fed570b83747086d0317f5e4bc325064f6c14319a9c4ff67L65-R68) Toolset and build infrastructure updates: * Bumped toolset dependency versions (such as `Microsoft.DotNet.Build.Tasks.Feed`, `Microsoft.DotNet.Arcade.Sdk`, and others) to `10.0.0-beta.26057.111` in `eng/Version.Details.xml`, with updated SHA references. NuGet package source changes: * Updated and added new NuGet package sources in `NuGet.config` to match the new dependency versions and remove obsolete sources.
There was a problem hiding this comment.
🟡 Changes recommended
The new test embeds an absolute build-machine analyzer path that is unavailable on remote Helix workers, causing it to fail before checking CA2252.
1 open issue
What changed in this PR
This PR addresses #40045 by suppressing CA2252 on the implicit XML namespace opt-in attribute emitted by MAUI’s .NET 10 XAML source generator. It targets builds using newer SDKs without changing preview warnings for manually applied attributes.
Changes:
- Wraps the generated attribute in a narrowly scoped CA2252 suppression.
- Adds a regression test that runs the CA2252 analyzer without an assembly-level preview opt-in.
- Records the resolved analyzer path in test assembly metadata.
| File | Description |
|---|---|
src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj |
Exposes the analyzer path through assembly metadata. |
src/Controls/tests/SourceGen.UnitTests/Maui40045Tests.cs |
Tests generated implicit namespace opt-in against CA2252. |
src/Controls/src/SourceGen/XamlGenerator.cs |
Suppresses CA2252 only around the generated attribute. |
Review effort: Balanced
| <!-- Used by Maui40045Tests to run the CA2252 analyzer over generated code --> | ||
| <Target Name="_AddNetAnalyzersPathMetadata" BeforeTargets="GetAssemblyAttributes" DependsOnTargets="ResolveLockFileAnalyzers"> | ||
| <ItemGroup> | ||
| <AssemblyMetadata Include="NetAnalyzersPath" Value="%(Analyzer.FullPath)" Condition="'%(Analyzer.Filename)' == 'Microsoft.CodeAnalysis.NetAnalyzers'" /> |
|
/rebase |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| <!-- Used by Maui40045Tests to run the CA2252 analyzer over generated code --> | ||
| <Target Name="_AddNetAnalyzersPathMetadata" BeforeTargets="GetAssemblyAttributes" DependsOnTargets="ResolveLockFileAnalyzers"> | ||
| <ItemGroup> | ||
| <AssemblyMetadata Include="NetAnalyzersPath" Value="%(Analyzer.FullPath)" Condition="'%(Analyzer.Filename)' == 'Microsoft.CodeAnalysis.NetAnalyzers'" /> |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - This embeds the build machine's absolute analyzer path in the test assembly. eng/helix.proj includes SourceGen.UnitTests for remote Windows/macOS execution, but its payload does not recreate that absolute location. GetPreviewFeaturesAnalyzers() passes the recorded path unchanged to AnalyzerFileReference and Assembly.LoadFrom, so a worker without the originating package-cache path fails while loading the analyzer, before checking CA2252. Copy both NetAnalyzers DLLs into the test output/payload and resolve their paths relative to the deployed test assembly.
…on backports (#40217) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change **Explicit release-target exception:** this PR intentionally targets the new `release/10.0.1xx-sr14` branch. `main`, `net11` and the inflight lanes are now .NET 11, so .NET 10 SR14 is cut from the SR13 release head (`release/10.0.1xx-sr14` was created at `54d76458e0`, the tip of `release/10.0.1xx-sr13`, which already includes all post-cut SR13 fixes #39830, #39855, #39879, #39891 and the servicing/stable configuration from #39774). This PR brings the .NET 10 changes needed since SR13: 1. **Backport #39887** – `[Windows] Prevent duplicate Shell startup navigation from stale tab selection events`. Fixes #39859 (regressed in 10.0.120); it was merged only to `main`. Clean `cherry-pick -x`. 2. **Backport #40132** – `Fix custom Shape.PathForBounds dispatch regression`. Fixes #40129 (regressed in 10.0.130); it was merged only to `candidate/11.0.1xx-sr2`. The unrelated .NET 11 `eng/release-rollover.json` change from that commit is excluded (file does not exist on the .NET 10 line). 3. **Version bump** – `PatchVersion` 130 → 140 in `eng/Versions.props`. Servicing label and `StabilizePackageVersion=true` are inherited from SR13. Reviewed and intentionally **not** included: - #40136 (`net10.0` Publish-Build-Assets cleanup): SR13 has no `Publish-Build-Assets` references, so nothing to remove. - #39882 (re-land of the CollectionView2 height fix): SR13 already carries the revert #39855 that fixed #39847; re-landing is a fix-forward, not a regression fix. - #40213 (`[net10.0][XSG]` CA2252 suppression, issue #40045): still open/unmerged; can be backported once approved. - Other `regressed-in-10.0.1x0` issues closed since the SR13 cut (#38622, #39557/#39681, #39722) are already fixed on SR13 or were fixed outside MAUI. Keep in draft pending review and CI. This PR does not tag, publish, or authorize a release; the internal dnceng mirror of `release/10.0.1xx-sr14` has not been created. #### Validation Using the pinned SDK `10.0.113` provisioned by `eng/common/dotnet.sh`: - `dotnet msbuild eng/Versions.props -getProperty:PatchVersion,SdkBandVersion,PreReleaseVersionLabel,StabilizePackageVersion,DotNetFinalVersionKind` → `140`, `10.0.100`, `servicing`, `true`, `release`. `xmllint --noout eng/Versions.props` passed. - `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj -f net10.0 --filter FullyQualifiedName~StrokeShapeTests` (platform TFMs disabled): **passed 59/59**. With `Shape.cs` reverted to SR13: **failed 3/59** (the new `CustomShapeReimplementingIShape*` tests); restored: **passed 59/59**. - #39887 is Windows-only (`ShellItemHandler.Windows.cs` + Windows device test) and was not built locally on macOS; it relies on CI. ### Issues Fixed Fixes #39859 Fixes #40129 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ---------
Preserve the release branch's configuration and the original source generator fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The tests embed build-machine analyzer paths unavailable on separate Helix workers, causing analyzer loading to fail unless the DLLs and required dependencies are deployed and resolved relative to the test assembly.
2 open issues
Review effort: Balanced
| var netAnalyzersPath = typeof(Maui40045Tests).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>() | ||
| .First(a => a.Key == "NetAnalyzersPath").Value!; | ||
| var loader = new AnalyzerLoader(); | ||
| var analyzers = new[] { netAnalyzersPath, Path.Combine(Path.GetDirectoryName(netAnalyzersPath)!, "Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll") } |
This comment has been minimized.
This comment has been minimized.
|
/rebase |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| <!-- Used by Maui40045Tests to run the CA2252 analyzer over generated code --> | ||
| <Target Name="_AddNetAnalyzersPathMetadata" BeforeTargets="GetAssemblyAttributes" DependsOnTargets="ResolveLockFileAnalyzers"> | ||
| <ItemGroup> | ||
| <AssemblyMetadata Include="NetAnalyzersPath" Value="%(Analyzer.FullPath)" Condition="'%(Analyzer.Filename)' == 'Microsoft.CodeAnalysis.NetAnalyzers'" /> |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - This embeds the build machine's absolute analyzer path in the test assembly. eng/helix.proj includes SourceGen.UnitTests for remote Windows/macOS execution, but its payload does not recreate that absolute location. GetPreviewFeaturesAnalyzers() passes the recorded path unchanged to AnalyzerFileReference and Assembly.LoadFrom, so a worker without the originating package-cache or SDK path fails while loading the analyzer, before checking CA2252. Copy both NetAnalyzers DLLs and required dependencies into the test output/payload and resolve their paths relative to the deployed test assembly.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. 🧪 Unit tests
Execution log excerptsWithout fix With fix PR head: 3ce3fb86. Without-fix baseline: b474cdfe. |


Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
On MAUI 10.0.x, when
MauiAllowImplicitXmlnsDeclarationis defined, the XAML source generator emits[assembly: AllowImplicitXmlnsDeclaration]intoGlobalXmlns.g.cs. That attribute is marked[RequiresPreviewFeatures].CA2252 is suppressed only if the app assembly carries
[assembly: RequiresPreviewFeatures]. The SDK adds that attribute only whenEnablePreviewFeatures=trueand the project targets the SDK's latest TFM (IsNetCoreAppTargetingLatestTFM). Anet10.0app built with the .NET 11 SDK therefore fails withGlobalXmlns.g.cs(15,12): error CA2252. Visual Studio picked a .NET 10 SDK, which is why the build passed there and failed from the CLI.Defining
MauiAllowImplicitXmlnsDeclarationis already the explicit opt-in, and the runtime, XamlC and SourceGen paths only check that the attribute is present. So the generator now wraps the emitted attribute in#pragma warning disable/restore CA2252. The public attribute is unchanged; user code that applies it by hand still gets CA2252 as before.Tests:
Maui40045TestsrunsXamlGeneratorwith theMauiAllowImplicitXmlnsDeclarationsymbol on a compilation that has no[assembly: RequiresPreviewFeatures], then runs the real CA2252 analyzer fromMicrosoft.CodeAnalysis.NetAnalyzersover the result. The analyzer path comes from the project's resolved@(Analyzer)items.Validation:
dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter FullyQualifiedName~Maui40045: passes with the fix. It fails without the fix withGlobalXmlns.g.cs(15,12): error CA2252.dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj: 180 passed, 0 failed.net10.0project on the .NET 11 RC2 SDK withMicrosoft.Maui.Controls10.0.130, the define andEnablePreviewFeatures=truefails with CA2252. With the patchedMicrosoft.Maui.Controls.SourceGen.dllswapped in, it builds..NET 11 / main: no change needed. The generator no longer emits the attribute (#33834), and the attribute is
[Obsolete]instead of preview-gated.Microsoft.Maui.Controls11.0.10 builds cleanly with the same settings on bothnet11.0(withGenerateRequiresPreviewFeaturesAttribute=false) andnet10.0.Issues Fixed
Fixes #40045