Copilot instructions
.github/instructions/templates.instructions.mdCopilot instructions
Quality
92/100
Scores the file, not the repository.Length
407 words
9 headings · 3 code blocksRepository
23k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.12345# Working with .NET MAUI Templates67## 1. Overview89When modifying files in the `src/Templates/` directory, you must follow special template semantics and conventions to ensure the templates work correctly when users create new projects. This guide covers conditional compilation directives, naming conventions, file exclusions, and testing procedures.1011## 2. Conditional Compilation1213Templates use special comment markers to control how preprocessor directives are processed during template instantiation.1415### Build-Time Directives (Platform-Specific)1617Platform-specific `#if` directives (like `#if WINDOWS`, `#if ANDROID`, `#if IOS`, `#if MACCATALYST`) must be wrapped with `//-:cnd:noEmit` and `//+:cnd:noEmit` markers:1819```csharp20//-:cnd:noEmit21#if WINDOWS22 // Windows-specific code23#endif24//+:cnd:noEmit25```2627**Why?** These markers tell the template engine to preserve these directives in the generated code exactly as-is, so they will be evaluated at compile-time when the user builds their project.2829**Examples:**30```csharp31//-:cnd:noEmit32#if DEBUG33 builder.Logging.AddDebug();34#endif35//+:cnd:noEmit3637//-:cnd:noEmit38#if IOS || MACCATALYST39 handlers.AddHandler<CollectionView, CollectionViewHandler2>();40#endif41//+:cnd:noEmit4243//-:cnd:noEmit44#if WINDOWS45 Microsoft.Maui.Controls.Handlers.Items.CollectionViewHandler.Mapper.AppendToMapping(46 "KeyboardAccessibleCollectionView",47 (handler, view) => { /* ... */ });48#endif49//+:cnd:noEmit50```5152### Template-Time Directives (Template Parameters)5354Template parameter directives (like `#if (IncludeSampleContent)`) do NOT use the `//-:cnd:noEmit` markers:5556```csharp57#if (IncludeSampleContent)58using CommunityToolkit.Maui;59#endif60```6162**Why?** These directives are evaluated when the template is instantiated (when user runs `dotnet new maui`), not when the code is compiled.6364## 3. Naming and Placeholders6566- Template project names use placeholders like `MauiApp._1` which get replaced with the user's actual project name67- Namespaces follow the same pattern: `namespace MauiApp._1;`68- These will be transformed to the user's chosen project name during template instantiation6970## 4. Files to Avoid Editing7172Never modify auto-generated files in templates:73- `cgmanifest.json` - Auto-generated component governance manifest74- `templatestrings.json` - Auto-generated localization file7576These files are regenerated during the build process and should not be manually edited.7778## 5. Testing and Verification7980When making changes to templates:811. Build the template project: `dotnet build src/Templates/src/Microsoft.Maui.Templates.csproj`822. For comprehensive testing, use the `build.ps1` script in the Templates directory to pack, install, and test the template833. Verify the generated project compiles for all target platforms8485## 6. Quick Reference Table8687| Directive Type | Wrapper Needed | Example |88| --- | --- | --- |89| Platform-specific (`#if WINDOWS`, `#if ANDROID`, etc.) | ✅ Yes - use `//-:cnd:noEmit` | Build-time platform detection |90| Debug mode (`#if DEBUG`) | ✅ Yes - use `//-:cnd:noEmit` | Build configuration |91| Template parameters (`#if (IncludeSampleContent)`) | ❌ No | Template instantiation options |92
Also in dotnet/maui
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotnet/maui.github/instructions/collectionview-handler-detection.instructions.md · 23k | Copilot instructions | stylegitdo-not | 73/100 | 3 days ago | |
| dotnet/maui.github/copilot-instructions.md · 23k | Copilot instructions | setuptestlint-formatstyle+6 | 76/100 | 3 days ago | |
| dotnet/maui.github/instructions/android.instructions.md · 23k | Copilot instructions | buildstyle | 70/100 | 3 days ago | |
| dotnet/maui.github/instructions/ci-copilot-pipeline-security.instructions.md · 23k | Copilot instructions | gitsecuritydeploymentdo-not+1 | 76/100 | 3 days ago | |
| dotnet/maui.github/instructions/collectionview-android.instructions.md · 23k | Copilot instructions | stylearchperformanceagent-behaviour | 52/100 | 3 days ago | |
| dotnet/maui.github/instructions/collectionview-ios.instructions.md · 23k | Copilot instructions | styleperformance | 48/100 | 3 days ago | |
| dotnet/maui.github/instructions/collectionview-windows.instructions.md · 23k | Copilot instructions | stylearch | 52/100 | 3 days ago | |
| dotnet/maui.github/instructions/handler-patterns.instructions.md · 23k | Copilot instructions | styledo-not | 55/100 | 3 days ago | |
| dotnet/maui.github/instructions/helix-device-tests.instructions.md · 23k | Copilot instructions | setupbuildtestarch | 74/100 | 3 days ago | |
| dotnet/maui.github/instructions/integration-tests.instructions.md · 23k | Copilot instructions | setupteststyledo-not | 92/100 | 3 days ago | |
| dotnet/maui.github/instructions/layout-system.instructions.md · 23k | Copilot instructions | archapiperformancedo-not | 55/100 | 3 days ago | |
| dotnet/maui.github/instructions/performance-hotpaths.instructions.md · 23k | Copilot instructions | styleperformancedo-not | 55/100 | 3 days ago | |
| dotnet/maui.github/instructions/public-api.instructions.md · 23k | Copilot instructions | apido-not | 59/100 | 3 days ago | |
| dotnet/maui.github/instructions/safe-area-ios.instructions.md · 23k | Copilot instructions | stylegit | 43/100 | 3 days ago | |
| dotnet/maui.github/instructions/sandbox.instructions.md · 23k | Copilot instructions | buildteststyletesting-strategy+4 | 81/100 | 3 days ago | |
| dotnet/maui.github/instructions/threading-async.instructions.md · 23k | Copilot instructions | styleui | 48/100 | 3 days ago | |
| dotnet/maui.github/instructions/uitests.instructions.md · 23k | Copilot instructions | setupbuildteststyle+5 | 79/100 | 3 days ago | |
| dotnet/maui.github/instructions/xaml-unittests.instructions.md · 23k | Copilot instructions | teststyledocs | 70/100 | 3 days ago |
Diff against .github/instructions/collectionview-handler-detection.instructions.md Diff against .github/copilot-instructions.md Diff against .github/instructions/android.instructions.md Diff against .github/instructions/ci-copilot-pipeline-security.instructions.md Diff against .github/instructions/collectionview-android.instructions.md Diff against .github/instructions/collectionview-ios.instructions.md Diff against .github/instructions/collectionview-windows.instructions.md Diff against .github/instructions/handler-patterns.instructions.md Diff against .github/instructions/helix-device-tests.instructions.md Diff against .github/instructions/integration-tests.instructions.md Diff against .github/instructions/layout-system.instructions.md Diff against .github/instructions/performance-hotpaths.instructions.md Diff against .github/instructions/public-api.instructions.md Diff against .github/instructions/safe-area-ios.instructions.md Diff against .github/instructions/sandbox.instructions.md Diff against .github/instructions/threading-async.instructions.md Diff against .github/instructions/uitests.instructions.md Diff against .github/instructions/xaml-unittests.instructions.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotnet/roslyn.github/instructions/Compiler.instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 99/100 | 3 days ago | |
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 97/100 | 3 days ago | |
| ardalis/CleanArchitecture.github/copilot-instructions.md · 18k | Copilot instructions | buildteststylearch+4 | 96/100 | 3 days ago | |
| dotnet/maui.github/instructions/integration-tests.instructions.md · 23k | Copilot instructions | setupteststyledo-not | 92/100 | 3 days ago | |
| we-promise/sure.github/copilot-instructions.md · 9.3k | Copilot instructions | setuptestlint-formatstyle+10 | 88/100 | 2 days ago | |
| microsoft/WSL.github/copilot-instructions.md · 33k | Copilot instructions | setupbuildtestlint-format+7 | 88/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/start-native-execution.instructions.md · 55k | Copilot instructions | buildstylearchgit+1 | 86/100 | 3 days ago | |
| hackiftekhar/IQKeyboardManager.github/copilot-instructions.md · 17k | Copilot instructions | setupbuildtestarch+5 | 85/100 | 3 days ago |
