diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 00000000..f6f73698 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,26 @@ +# Copilot instructions: Windows Community Toolkit + +Stable WinUI components (`components//{src,samples,tests}`) shipped as `CommunityToolkit.Uwp.*` (UWP, WinUI 2) and `CommunityToolkit.WinUI.*` (Windows App SDK and Uno, WinUI 3) NuGet packages. The build system, sample/test heads, generators and scripts live in the `tooling/` git submodule; this repo is the consumer layout they are designed for, so tooling scripts run in place here. New features start in Windows Community Toolkit Labs (`CommunityToolkit/Labs-Windows`); this repo takes fixes and components migrated from Labs (the PR template asks for a link to the migration approval). + +## Tooling docs (not auto-loaded) +Copilot only loads `.github` from this repo root, so read these explicitly: +- `tooling/.github/copilot-instructions.md`: before editing any code or build file (it has the conditional-compilation, MSBuild-condition and license-header rules). +- `tooling/.github/instructions/multitarget.instructions.md`: before touching `MultiTarget.props`, `Dependencies.props` conditions, TFMs, identity properties or package ids. +- `tooling/.github/instructions/powershell-scripts.instructions.md`: before running any tooling script (side effects, prompts that hang, exit code 0 on failure). +- `tooling/.github/instructions/dotnet-templates.instructions.md`: when adding a component or adding files to an existing component's tests/samples (test projitems list files by hand). +- `tooling/.github/instructions/source-generators.instructions.md`, `tooling/.github/skills/validate-in-consumer-layout/SKILL.md`: only for changes *to* tooling, which belong in the tooling repo. + +Inside those files "this repo" means tooling and "consumer repo" means this repo; their "Layout assumption" section and "never run scripts from your checkout" rule do not apply here. To validate changes in this repo use `.github/skills/validate-component-changes`. + +## Build configuration +- Package version is `..[-]` from `MajorVersion`/`MinorVersion` in the root `Directory.Build.props`. On a `rel/x.y.z[-pre]` branch CI takes only the patch and prerelease parts from the branch name, so `x.y` must match the props. +- Release is the real gate: it adds `TreatWarningsAsErrors` and `EnforceCodeStyleInBuild`; Debug does not (nullable warnings are errors in both). Fix the code rather than adding `NoWarn`, `WarningsNotAsErrors` or pragmas, and don't remove the existing exceptions in the Release group. +- CI job `Xaml-Style-Check` gates the whole `build` matrix. `./ApplyXamlStyling.ps1` with no flags reads `git status`, which collapses a new untracked folder to one entry, so a brand-new component's XAML is skipped: `git add` it first and use `-Staged`. + +## Never +- Commit changes to the tracked `tooling/MultiTarget/EnabledMultiTargets.props` that tooling scripts rewrite (the submodule shows as modified in `git status`): `git -C tooling checkout -- MultiTarget/EnabledMultiTargets.props`. +- Edit files under `tooling/` as part of a change here: they are not part of this repo's commits. Change tooling in its own repo, then bump the submodule pointer in its own commit; a pointer to an unmerged tooling branch is temporary and must be re-pointed to tooling `main` once that merges. CI hard-codes the `tooling/CommunityToolkit.Tooling.SampleGen.Tests` output path in `build.yml`: a bump that moves it needs a matching workflow edit. +- Hand-edit `catalog/toolkit-samples.json` (generated; see `.github/instructions/components.instructions.md`). +- Remove or rename `ToolkitConvertersSourceProject`, `ToolkitSettingsControlsSourceProject`, `ToolkitExtensionsSourceProject` or `ToolkitTriggersSourceProject`: tooling's sample/test heads silently fall back to a pinned preview NuGet package when they are unset. +- Put MultiTarget- or tooling-dependent logic in the root `Directory.Build.targets`: it also applies to `tools/`, which only isolates itself from the root `Directory.Build.props`. +- Run `GenerateAllSolution.bat` from automation: it passes no `-Launch`, so it opens Visual Studio. Call `tooling/GenerateAllSolution.ps1 ... -Launch $false` instead. diff --git a/.github/instructions/components.instructions.md b/.github/instructions/components.instructions.md new file mode 100644 index 00000000..0de2cb28 --- /dev/null +++ b/.github/instructions/components.instructions.md @@ -0,0 +1,21 @@ +--- +applyTo: "components/**,catalog/**,tools/**" +--- +# Components, sample index and `tools/` + +## Components +- Prefer `$(ToolkitSourceProject)` from the root `Directory.Build.props` over relative paths for sibling component references (add the property there if it is missing). +- Component projects reference siblings unconditionally, so a referenced component must be buildable on every MultiTarget the referencing one builds for (e.g. a component that builds for Uno cannot depend on a `uwp;wasdk`-only one). +- Converters, SettingsControls, Extensions and Triggers are project-referenced by every sample app head (Extensions also by every test head), and `tooling/` code consumes their public API: a break or API change in one of them breaks every head, and the tooling side cannot be fixed from here. +- The sample index takes `nugetPackage` from the `src` csproj *file name*, which is the WinUI-variant package id (`CommunityToolkit.WinUI...`; the UWP variant swaps the variant segment). The tooling default `PackageId` has no `.Controls`, so a control must set `PackageId` to `$(PackageIdPrefix).$(PackageIdVariant).Controls.$(ToolkitComponentName)` and name its csproj to match; the `ctk-component` template does not do this. Set it *after* the `ToolkitComponent.SourceProject.props` import, which is what defines `PackageIdVariant`. + +## Sample index (`catalog/toolkit-samples.json`) +`catalog/README.md` describes the file and the `generate`/`check` commands. Easy to miss: +- It is derived from `components/*/samples/**/*.md` (only files with front matter), `*.xaml.cs` (`[ToolkitSample]`) and the paired `.xaml`, the single csproj in each `src/` and the type/namespace/extension-method declarations in `components/*/src/**/*.cs` (they narrow `usings`). A pure `src` change can therefore make the index stale. After touching any of these run `generate` and commit the result with the change. +- Run `check` and the tests on a tree without sample build output: building a sample project copies its `*.md`/`*.xaml.cs` into `components/*/samples/bin`, which the exporter does not exclude, so both then fail with "sample id ... is already declared". Delete that output first (see the validation skill's clean-up). +- `dotnet test tools/SampleIndexExporter.Tests` (also run by CI) is stricter than `check`: it also fails on unreferenced `[ToolkitSample]`s, withheld samples and sample-less docs missing from its allow-list (`CoverageTests`). +- An entry id is the slug of the *markdown file name*, must be unique across all components (a collision is an error) and is published as a stable id: renaming a docs file changes it. +- The exporter and its tests target a runtime older than the SDK in `global.json`. If it is not installed, set `$env:DOTNET_ROLL_FORWARD='Major'` (persists for the session) before `dotnet run`/`dotnet test`. + +## `tools/` +- The CI job for `tools/` does not check out `tooling/` or install workloads, so these projects must not reference `tooling/` or WinUI/Uno. diff --git a/.github/skills/validate-component-changes/SKILL.md b/.github/skills/validate-component-changes/SKILL.md new file mode 100644 index 00000000..a3e862a9 --- /dev/null +++ b/.github/skills/validate-component-changes/SKILL.md @@ -0,0 +1,48 @@ +--- +name: validate-component-changes +description: Build and test changes to components, sample docs/XAML, root props or the sample index in this repo the way CI does (generate solution, Release msbuild, tests, pack, XAML style, sample index). Use before declaring any change under components/, Directory.Build.props/targets, Windows.Toolkit.Common.props, catalog/ or tools/ done. This repo is already the consumer layout, so tooling scripts run in place. +--- + +# Validate changes in this repo + +Mirrors `.github/workflows/build.yml`; run from the repo root on Windows. Read `tooling/.github/instructions/powershell-scripts.instructions.md` first: the scripts have side effects and report failures with exit code 0, so read their output. + +## Prerequisites +- `msbuild.exe` from Visual Studio on `PATH` (Developer shell, or prepend `\MSBuild\Current\Bin\amd64`); otherwise `GenerateSingleSolution.ps1` waits for a keypress. `vstest.console.exe` lives in `\Common7\IDE\CommonExtensions\Microsoft\TestWindow`. +- `dotnet tool restore` once. Build requirements are in `tooling/ReadMe.md` (the root `ReadMe.md` is out of date); CI runs `uno-check` for every leg except `wasdk`, `wpf` and `linuxgtk`. +- If nuget.org is unreachable, restore fails; revert any local feed override in `nuget.config` before committing. + +## 1. Fast loop: one component +```powershell +./tooling/ProjectHeads/GenerateSingleSampleHeads.ps1 -MultiTargets wasdk -winui 3 -componentPath $PWD\components\ -Launch $false -IncludeReferencedProjects +msbuild.exe components\\.slnx /restore /nowarn:MSB4011 -p:Configuration=Release /m +``` +Use `-MultiTargets uwp -winui 2` for WinUI 2. Before building, check the output for `Generated solution` and that the `.slnx` lists the expected projects (the message is printed even if a reference failed to resolve). Without `-IncludeReferencedProjects`, sibling components (Extensions, Triggers, ...) are not in the `.slnx` and get built as **Debug**, so the Release warning gate does not apply to them. + +Tests, as CI runs them (`Tests.Uwp` for WinUI 2): +```powershell +vstest.console.exe (Get-ChildItem components\\heads\Tests.Wasdk -Recurse -Filter *.build.appxrecipe | Where-Object FullName -Match '\\Release\\' | Select-Object -First 1).FullName /Framework:FrameworkUap10 +``` +The WinAppSdk test host needs the .NET runtime matching the head's TFM; if it is missing, report the tests as not run. + +## 2. Release gate on source projects +```powershell +New-Item -ItemType Directory $env:TEMP\nupkgs -Force | Out-Null +./tooling/Build-Toolkit-Components.ps1 -Components -MultiTargets wasdk -WinUIMajorVersion 3 -Release -NupkgOutput $env:TEMP\nupkgs +``` +Builds each `src` project (and its dependencies) directly in Release; packs only because `-NupkgOutput` is given, and that folder must already exist. A component that does not support the MultiTarget is skipped with a warning and exit code 0. CI's package job uses `-MultiTargets all` per WinUI version. + +## 3. CI build legs (all components) +One leg per `build.yml` matrix entry (`uwp` with WinUI 2; the rest with WinUI 3): +```powershell +./tooling/GenerateAllSolution.ps1 -MultiTargets wasdk -WinUIMajorVersion 3 -Launch $false +msbuild.exe /restore /nowarn:MSB4011 /p:Configuration=Release /m CommunityToolkit.AllComponents.slnx +``` +A cold `wasdk` leg takes a few minutes. `wasdk` then runs the component tests like CI: `vstest.console.exe ./tooling/**/CommunityToolkit.Tests.wasdk.build.appxrecipe /Framework:FrameworkUap10`. `uwp` and `wasdk` share TFMs and output folders, so clean (step 5) when switching legs or after single-component builds: stale `samples/bin` output made the all-components test head fail with `APPX1101` (duplicate `*.xaml` payload). The all-components `uwp` leg finds no component tests (see tooling's multitarget instructions); UWP component tests only run from a single-component solution (step 1). + +## 4. Other CI jobs +- XAML style: `./ApplyXamlStyling.ps1 -Passive` checks every file; to fix your changes, `git add` them and run `./ApplyXamlStyling.ps1 -Staged`. +- Sample index: `dotnet run --project tools/SampleIndexExporter -- check` and `dotnet test tools/SampleIndexExporter.Tests`, **before building samples or after step 5** (sample build output breaks them; details and the runtime note are in `.github/instructions/components.instructions.md`). + +## 5. Clean up +Run `dotnet build-server shutdown` first: lingering MSBuild nodes lock `bin`/`obj` and make `git clean` fail partway. Preview with `git clean -ndX components` (ignored files include more than build output, e.g. `.vs/`, `*.user`), then `git clean -fdX components` (build output, `heads/`, `*.slnx`); delete the root `CommunityToolkit.AllComponents.slnx`; do the same in `tooling/` with `git -C tooling clean -fdX`; `git -C tooling checkout -- MultiTarget/EnabledMultiTargets.props`. `git status` and `git -C tooling status` must show only your intended changes. diff --git a/tooling b/tooling index 5668ff29..499fca65 160000 --- a/tooling +++ b/tooling @@ -1 +1 @@ -Subproject commit 5668ff2902fb91c780d30ff215202eead21d8593 +Subproject commit 499fca6579aeb48a8bfb08b997f2b11bf57895e4