Skip to content

Commit fe1284b

Browse files
committed
Address Uno generator review feedback
Use shared mobile target defaults and WINUI3 aliases, clarify Uno 5 API support and target-framework guidance, and document the test reference baseline with additional Uno.UI coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c08f9b4b-106c-4922-b1e8-ee02d89ee263
1 parent f7371bd commit fe1284b

6 files changed

Lines changed: 43 additions & 25 deletions

File tree

‎components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.Tests/Helpers/XamlFrameworkTest.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ namespace CommunityToolkit.GeneratedDependencyProperty.Tests.Helpers;
1919
/// <summary>
2020
/// Runs generation and analysis against an independently referenced XAML framework.
2121
/// </summary>
22+
/// <remarks>
23+
/// Both compilations use .NET 8 reference assemblies to cover the oldest supported modern .NET target,
24+
/// independently of the SDK running the tests. When raising that baseline, update both reference sets,
25+
/// the Basic.Reference.Assemblies.Net80 package reference, and the other test helpers together.
26+
/// </remarks>
2227
internal static class XamlFrameworkTest
2328
{
2429
public static PortableExecutableReference CreateFrameworkReference(string assemblyName, bool isInterface, string xamlNamespace = "Microsoft.UI.Xaml", string? filePath = null)

‎components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.Tests/Test_DependencyPropertyGenerator.Uno.cs‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ namespace CommunityToolkit.GeneratedDependencyProperty.Tests;
1515
partial class Test_DependencyPropertyGenerator
1616
{
1717
[TestMethod]
18-
[DataRow("Uno.UI", true, false)]
19-
[DataRow("Uno.UI", true, true)]
20-
[DataRow("Uno.WinUI", false, false)]
21-
[DataRow("Uno.WinUI", false, true)]
22-
[DataRow("Uno.UI", false, false)]
23-
[DataRow("Uno.UI", false, true)]
24-
[DataRow("Microsoft.WinUI", false, false)]
25-
public async Task XamlFramework_ValidOwners_CompileAndDoNotWarn(string assemblyName, bool isInterface, bool renamedReference)
18+
[DataRow("Uno.UI", true, false, false)]
19+
[DataRow("Uno.UI", true, true, false)]
20+
[DataRow("Uno.WinUI", false, false, false)]
21+
[DataRow("Uno.WinUI", false, true, false)]
22+
[DataRow("Uno.UI", false, false, false)]
23+
[DataRow("Uno.UI", false, true, false)]
24+
[DataRow("Microsoft.WinUI", false, false, false)]
25+
[DataRow("Uno.UI", true, false, true)]
26+
[DataRow("Uno.UI", true, true, true)]
27+
public async Task XamlFramework_ValidOwners_CompileAndDoNotWarn(string assemblyName, bool isInterface, bool renamedReference, bool useWindowsUIXaml)
2628
{
29+
string xamlNamespace = useWindowsUIXaml ? "Windows.UI.Xaml" : "Microsoft.UI.Xaml";
2730
PortableExecutableReference frameworkReference = XamlFrameworkTest.CreateFrameworkReference(
2831
assemblyName,
2932
isInterface,
33+
xamlNamespace,
3034
filePath: renamedReference ? @"C:\References\Unrelated.dll" : $@"C:\References\{assemblyName}.dll");
3135

3236
const string properties = """
@@ -61,8 +65,8 @@ partial void OnCountChanged(int value) { }
6165

6266
string source = $$"""
6367
using CommunityToolkit.WinUI;
64-
using Microsoft.UI.Xaml;
65-
using Microsoft.UI.Xaml.Controls;
68+
using {{xamlNamespace}};
69+
using {{xamlNamespace}}.Controls;
6670
6771
namespace MyApp;
6872
@@ -86,19 +90,19 @@ public partial class IndirectOwner : IntermediateControl
8690
}
8791
""";
8892

89-
Compilation compilation = XamlFrameworkTest.RunGenerator(source, frameworkReference);
93+
Compilation compilation = XamlFrameworkTest.RunGenerator(source, frameworkReference, useWindowsUIXaml);
9094

9195
XamlFrameworkTest.AssertEmits(compilation);
9296

93-
Assert.AreEqual(0, (await XamlFrameworkTest.GetAnalyzerDiagnosticsAsync(compilation)).Length);
97+
Assert.AreEqual(0, (await XamlFrameworkTest.GetAnalyzerDiagnosticsAsync(compilation, useWindowsUIXaml)).Length);
9498

9599
foreach (string ownerName in new[] { "DirectOwner", "ControlOwner", "IndirectOwner" })
96100
{
97101
string generatedSource = compilation.SyntaxTrees.Single(tree => Path.GetFileName(tree.FilePath) == $"MyApp.{ownerName}.g.cs").ToString();
98102

99-
StringAssert.Contains(generatedSource, "global::Microsoft.UI.Xaml.DependencyProperty.Register(");
103+
StringAssert.Contains(generatedSource, $"global::{xamlNamespace}.DependencyProperty.Register(");
100104
StringAssert.Contains(generatedSource, $"ownerType: typeof({ownerName})");
101-
StringAssert.Contains(generatedSource, "new global::Microsoft.UI.Xaml.PropertyMetadata(");
105+
StringAssert.Contains(generatedSource, $"new global::{xamlNamespace}.PropertyMetadata(");
102106
StringAssert.Contains(generatedSource, "defaultValue: \"Ready\"");
103107
StringAssert.Contains(generatedSource, "defaultValue: 42");
104108
StringAssert.Contains(generatedSource, "defaultValue: default(int)");

‎components/DependencyPropertyGenerator/samples/DependencyPropertyGenerator.md‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Install the package that matches your application's XAML framework from the [Com
3030
| --- | --- | --- |
3131
| WinUI 3 / Windows App SDK | `CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator` | `Microsoft.UI.Xaml` |
3232
| UWP | `CommunityToolkit.Labs.Uwp.DependencyPropertyGenerator` | `Windows.UI.Xaml` |
33-
| Uno Platform (WinUI) | `CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator` (see target frameworks below) | `Microsoft.UI.Xaml` |
33+
| Uno Platform 5.x (UWP API / Uno.UI) | `CommunityToolkit.Labs.Uwp.DependencyPropertyGenerator` (see target frameworks below) | `Windows.UI.Xaml` |
34+
| Uno Platform 5.x, 6.x, or 7.x (WinUI API / Uno.WinUI) | `CommunityToolkit.Labs.WinUI.DependencyPropertyGenerator` (see target frameworks below) | `Microsoft.UI.Xaml` |
3435

3536
Both packages expose the attribute in the `CommunityToolkit.WinUI` namespace. Install the package in the project that declares the generated properties, not just in an application that references that project.
3637

@@ -445,9 +446,11 @@ Do not combine embedded types with a reference to the package's runtime attribut
445446

446447
### Uno Platform
447448

448-
The WinUI package includes attribute assemblies for `net9.0-android35.0`, `net9.0-ios18.0`, and `net9.0-maccatalyst18.0`, alongside its Windows targets. These mobile targets use Uno dependencies rather than Windows App SDK. Reference the package normally on compatible Android, iOS, and Mac Catalyst targets; embedded mode is not required.
449+
Both packages include attribute assemblies for Android, iOS, and Mac Catalyst, alongside their Windows targets. Mobile TFMs and platform versions follow the Toolkit's shared `MultiTarget` configuration; check the package's supported frameworks for the exact TFMs in a particular release. These mobile targets use Uno dependencies rather than Windows App SDK. Reference the package normally on compatible mobile targets; embedded mode is not required.
449450

450-
The example uses the minimum supported C# version. Keep a newer language version if your project already uses one.
451+
Select the package by XAML API, not just the Uno version. Uno 5 supports both the UWP API (`Uno.UI`) and the WinUI API (`Uno.WinUI`); Uno 6 and 7 use the WinUI API. An existing Uno 5 UWP-API project can keep using `Windows.UI.Xaml` with the UWP package without migrating to the WinUI API.
452+
453+
For a WinUI-API project, use the WinUI package. The example uses the minimum supported C# version; keep a newer language version if your project already uses one.
451454

452455
```xml
453456
<ItemGroup>
@@ -461,11 +464,20 @@ The example uses the minimum supported C# version. Keep a newer language version
461464
</PropertyGroup>
462465
```
463466

464-
Other Uno targets, such as desktop and WebAssembly, do not yet have attribute assemblies in this package. Use the embedded-mode setup above on those targets: set `PrivateAssets="all"` and `ExcludeAssets="compile;runtime"` on the package reference and enable `EnableGeneratedDependencyPropertyAttributeEmbeddedMode`. Enable `EnableGeneratedDependencyPropertyEmbeddedMode` too if you use `GeneratedDependencyProperty.UnsetValue`. That setup can also be applied to every target of a multi-target project; keep the package's analyzer and build assets enabled, and do not combine embedded types with a reference to the attribute assembly.
467+
For an Uno 5 UWP-API project, use this package reference instead, and omit the explicit `false` setting above. The UWP package defaults `DependencyPropertyGeneratorUseWindowsUIXaml` to `true`:
468+
469+
```xml
470+
<ItemGroup>
471+
<PackageReference Include="CommunityToolkit.Labs.Uwp.DependencyPropertyGenerator"
472+
Version="PACKAGE_VERSION" />
473+
</ItemGroup>
474+
```
475+
476+
Other Uno targets, such as desktop and WebAssembly, do not yet have attribute assemblies in these packages. Use the embedded-mode setup above on those targets: set `PrivateAssets="all"` and `ExcludeAssets="compile;runtime"` on the appropriate package reference and enable `EnableGeneratedDependencyPropertyAttributeEmbeddedMode`. Enable `EnableGeneratedDependencyPropertyEmbeddedMode` too if you use `GeneratedDependencyProperty.UnsetValue`. That setup can also be applied to every TFM listed in a consuming project's `<TargetFrameworks>` property; this is independent of the Toolkit repository's `MultiTarget` build system. Keep the package's analyzer and build assets enabled, and do not combine embedded types with a reference to the attribute assembly.
465477

466-
Use `Microsoft.UI.Xaml` for Uno's WinUI API, regardless of whether its types are declared in `Uno.UI` or `Uno.WinUI`. The generator resolves the referenced framework symbols; no Uno version, assembly-file naming convention, or application-specific polyfill is required.
478+
Use `Windows.UI.Xaml` for Uno's UWP API and `Microsoft.UI.Xaml` for its WinUI API. The WinUI API namespace is the same regardless of whether its types are declared in an assembly named `Uno.UI` or `Uno.WinUI`; assembly names do not necessarily match the NuGet package name. The generator resolves the referenced framework symbols; no Uno version detection, assembly-file naming convention, or application-specific polyfill is required.
467479

468-
The same declarations work with Uno 6.x's interface-based `DependencyObject` and Uno 7.x's class-based layout. Uno's own generator supplies the framework implementation when a class directly implements the interface. If another imported namespace also provides a `GeneratedDependencyPropertyAttribute`, qualify the Toolkit attribute as `[CommunityToolkit.WinUI.GeneratedDependencyProperty]`.
480+
The same declarations work with Uno 5.x and 6.x's interface-based `DependencyObject` and Uno 7.x's class-based layout. Uno's own generator supplies the framework implementation when a class directly implements the interface. If another imported namespace also provides a `GeneratedDependencyPropertyAttribute`, qualify the Toolkit attribute as `[CommunityToolkit.WinUI.GeneratedDependencyProperty]`.
469481

470482
### Preserving embedded attributes
471483

‎components/DependencyPropertyGenerator/src/CommunityToolkit.WinUI.DependencyPropertyGenerator.csproj‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
<!-- This library doesn't need XAML support, so we can just target 17763 -->
2121
<UwpTargetFrameworks>uap10.0.17763;net8.0-windows10.0.17763.0;net9.0-windows10.0.17763.0;</UwpTargetFrameworks>
22-
<AndroidLibTargetFrameworks>net9.0-android35.0;</AndroidLibTargetFrameworks>
23-
<iOSLibTargetFrameworks>net9.0-ios18.0;</iOSLibTargetFrameworks>
24-
<MacOSLibTargetFrameworks>net9.0-maccatalyst18.0;</MacOSLibTargetFrameworks>
2522
</PropertyGroup>
2623

2724
<!-- Sets this up as a toolkit component's source project -->

‎components/DependencyPropertyGenerator/src/GeneratedDependencyProperty.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if WINAPPSDK
5+
#if WINUI3
66
using DependencyProperty = Microsoft.UI.Xaml.DependencyProperty;
77
#else
88
using DependencyProperty = Windows.UI.Xaml.DependencyProperty;

‎components/DependencyPropertyGenerator/src/GeneratedDependencyPropertyAttribute.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#if NET8_0_OR_GREATER
77
using System.Diagnostics.CodeAnalysis;
88
#endif
9-
#if WINAPPSDK
9+
#if WINUI3
1010
using DependencyObject = Microsoft.UI.Xaml.DependencyObject;
1111
using DependencyProperty = Microsoft.UI.Xaml.DependencyProperty;
1212
using PropertyMetadata = Microsoft.UI.Xaml.PropertyMetadata;

0 commit comments

Comments
 (0)