Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The focused import-ordering fix, consistent filtering, and regression coverage address the reported issue with no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes #18525 by letting projects remove individual Uno SDK implicit usings and omitting Uno.UI for WinAppSDK-only libraries.
Changes:
- Moves implicit usings before the project body so
Using Removeworks. - Shares the WinAppSDK-only condition between package and namespace filtering.
- Adds regression coverage and documents supported opt-outs.
| File | Description |
|---|---|
src/Uno.Sdk/targets/Uno.Sdk.After.targets |
Defines the shared library-filtering condition. |
src/Uno.Sdk/targets/Uno.Implicit.Packages.ProjectSystem.targets |
Reuses the condition and explains package ordering. |
src/Uno.Sdk/targets/Uno.Implicit.Namespaces.targets |
Removes the late namespace definitions. |
src/Uno.Sdk/targets/Uno.Implicit.Namespaces.props |
Defines removable, conditional implicit usings. |
src/Uno.Sdk/targets/Uno.Common.targets |
Removes the old namespace import. |
src/Uno.Sdk/Sdk/Sdk.props.buildschema.json |
Documents namespace suppression. |
src/Uno.Sdk/Sdk/Sdk.props |
Imports implicit usings before the project body. |
src/SourceGenerators/Uno.UI.Tasks.Tests/Given_UnoSdkImplicitUsings.cs |
Adds 15 SDK evaluation cases. |
doc/articles/features/using-the-uno-sdk.md |
Explains implicit usings and package opt-outs. |
Review effort: Balanced
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-25567/docs/index.html |
|
Tick the box to add this pull request to the merge queue (same as
|
The Uno.Sdk added its implicit Using items in Uno.Implicit.Namespaces.targets, which Uno.Common.targets imports from Sdk.targets, after the project body. A <Using Remove="..." /> in the project was evaluated before the item it was meant to remove, so it had no effect, and DisableImplicitUnoNamespaces was the only way out. Define the items in a props file imported right after the .NET SDK's Sdk.props, as the .NET SDK does with its own implicit usings. The DisableImplicitUnoNamespaces check moves from the import to the item group. Item conditions are evaluated after all properties, so a value set in the project body still applies, and one set later, in a Directory.Build.targets for example, now applies too: the import condition was evaluated before that file. Fixes unoplatform#18525
With DisableImplicitUnoWinAppSdkPackages, a library's Windows App SDK target no longer references Uno.WinUI, which is what provides the Uno.UI namespace there, but the Uno.Sdk still added global using Uno.UI. With ImplicitUsings on, that target failed with CS0246. Skip that using under the same condition that strips the Uno packages, now computed once in _UnoIsWinAppSdkOnlyLibrary so the two cannot drift. Both readers are item conditions, so the property is defined last, in Uno.Sdk.After.targets: the property is still honored when set in a Directory.Build.targets, as the strip's own item condition did. The other Uno implicit usings stay: the Windows App SDK, the Windows SDK and the BCL provide them on that target.
Evaluates the in-repo Uno.Sdk around a project body, the way SamplesApp imports it, in a temporary directory with its own Directory.Build.props and Directory.Build.targets, and checks the Using items: a Remove in the body applies, ImplicitUsings and DisableImplicitUnoNamespaces apply from the body and from a Directory.Build.targets, and a WinAppSDK-only library gets neither Uno.WinUI nor the Uno.UI using on Windows, whether it opts in from the body, from an inner build or from a Directory.Build.targets, while its other targets and application heads keep both. Also checks that leaving a feature out of UnoFeatures on Windows leaves its packages out there.
Lists the Uno.Sdk implicit usings and how to remove one or all of them, and notes that a WinAppSDK-only library gets no Uno.UI using on Windows, and what to add when Uno.WinUI reaches that target anyway. A static <PackageReference Remove="..." /> does not remove an implicit package: the SDK adds them after the project body on purpose, so a PackageReference the project declares replaces the implicit one instead of duplicating it, and UnoImplicitPackages adds them again before restore. Say so where the packages are added and in the docs, and point to the supported routes: the DisableImplicitUno* properties and a per-target UnoFeatures.
3501969 to
df3ad24
Compare
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-25567/docs/index.html |
MartinZikmund
left a comment
There was a problem hiding this comment.
@mikernet thanks, this is a really clean fix, and the write-up made it easy to review. The SDK side checks out: the Uno usings now sit right after the .NET SDK's Sdk.props, same as the .NET SDK's own, so a <Using Remove> in the body works. The item conditions read final property values, so DisableImplicitUnoNamespaces from a Directory.Build.targets now counts too. Moving _UnoIsWinAppSdkOnlyLibrary into Uno.Sdk.After.targets is the right spot. The new .props is covered by the targets/**/*.props glob in Uno.Sdk.csproj, so it gets packed. Default experience: same set of usings, same Sdk="Uno" metadata, and workarounds that removed usings inside a target keep working.
One thing to change before merge, in the test harness only:
Given_UnoSdkImplicitUsingsbrings its ownMSBuildrunner, butUno.UI.Tasks.Tests/DotnetMSBuild.csalready exists for exactly this, andGiven_UnoSdkLateBrowserWasmTargetFrameworkuses it with the same import-the-SDK-by-path pattern. The local copy is missing a few things that matter on CI (details inline). Could you switch toDotnetMSBuild.Run(RepositoryPaths.Root, ...), parseStandardOutputonly, and useDotnetMSBuild.TryDeleteDirectoryin thefinally?
Nit, optional: the test file starts with two BOMs (EF BB BF EF BB BF). It compiles fine, but it's worth dropping the extra one.
Heads-up: the main CI pipeline hasn't run on this yet, so the new tests haven't been run on CI agents.
The test brought its own dotnet msbuild runner: no time limit, no DOTNET_NOLOGO, and run from the temp folder, so global.json did not pick the SDK. Parsing stdout with stderr appended could also break on anything MSBuild writes to stderr. Use DotnetMSBuild from the repo root, parse stdout only, and drop the doubled BOM.
|
Switched |
GitHub Issue: closes #18525
PR Type:
🐞 Bugfix
What changed? 🚀
The Uno.Sdk added its implicit
Usingitems inUno.Implicit.Namespaces.targets, whichUno.Common.targetsimports fromSdk.targets, after the project body. A<Using Remove="Uno.UI" />in the project therefore ran before the item it was meant to remove and did nothing.DisableImplicitUnoNamespaces, which drops them all, was the only way out.Uno.Implicit.Namespaces.props, imported right after the .NET SDK'sSdk.props, where the .NET SDK defines its own implicit usings. TheImplicitUsingsandDisableImplicitUnoNamespaceschecks are item conditions, evaluated after every property, so values set in the project body or in aDirectory.Build.targetsapply. Before,DisableImplicitUnoNamespacesset after the project body, in aDirectory.Build.targetsfor example, was ignored; it now applies.Uno.UIusing on Windows. WithDisableImplicitUnoWinAppSdkPackages, that target has noUno.WinUI, which provides the namespace there, soglobal using global::Uno.UI;failed with CS0246 wheneverImplicitUsingswas on. The using now follows the condition that strips the packages, computed once in_UnoIsWinAppSdkOnlyLibrary. It is defined last, inUno.Sdk.After.targets, so the property still counts when set in aDirectory.Build.targets. The other Uno usings stay: the Windows App SDK, the Windows SDK and the BCL provide them.using-the-uno-sdk.md. It also says that a static<PackageReference Remove>cannot remove an implicit package, even in aDirectory.Build.targets: the SDK adds them after the body on purpose, so that an explicitPackageReferencereplaces one, and itsUnoImplicitPackagestarget adds them again before restore. It lists the supported opt-outs instead.This is a deliberate trade-off for one case: a WinAppSDK-only library that gets
Uno.WinUIback on Windows, explicitly or through a feature package such as Toolkit, and relies on theUno.UIusing there now adds<Using Include="Uno.UI" />. The property only exists since 6.7, and without such a package the same library never compiled.Tests
Given_UnoSdkImplicitUsings(Uno.UI.Tasks.Tests, 15 cases) evaluates the in-repo SDK around a project body, with its ownDirectory.Build.propsandDirectory.Build.targets. It runsdotnet msbuildthrough the sharedDotnetMSBuildrunner from the repository root, so the repo'sglobal.jsonpicks the SDK, and parses only its standard output. TheRemovecases fail with the items imported back where they were, the WinAppSDK-only cases fail without theUno.UIcondition, and theDirectory.Build.targetscase fails with the property defined inUno.Common.targets. Uno.UI.Tasks.Tests: 211/211 pass.Runtime, with locally packed SDKs: a WinAppSDK-only library, opting in from the project or from a
Directory.Build.targets, fails with CS0246 on master (as it does with Uno.Sdk 6.7.30) and builds with this change, and a<Using Remove>in the project takes the namespace out ofGlobalUsings.g.cs.PR Checklist ✅
Screenshots Compare Test Runresults.