Skip to content

Commit 855887f

Browse files
[copilot] update instructions file (#10355)
There is a new Copilot > Configure Chat... > Generate Instructions menu in VS Code. I let it run and update the file, and accepted the parts that looked useful. The most important thing, it found various links to `.md` files that were broken! This makes the file about 50% smaller, which may give @copilot more context window to work with.
1 parent 36e9923 commit 855887f

File tree

1 file changed

+47
-197
lines changed

1 file changed

+47
-197
lines changed

.github/copilot-instructions.md

Lines changed: 47 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,35 @@
11
# Instructions for AIs
22

3-
This repository is **.NET for Android** (formerly Xamarin.Android), the open-source bindings and tooling for Android development using .NET languages like C#.
4-
5-
This is the main branch targeting **.NET 10**.
6-
7-
## Repository Overview
8-
9-
.NET for Android provides:
10-
- Android SDK bindings in C# (`src/Mono.Android/`)
11-
- MSBuild tasks for building Android apps (`src/Xamarin.Android.Build.Tasks/`)
12-
- Native runtime components (`src/native/`)
13-
- Build tooling and infrastructure (`build-tools/`)
14-
- Comprehensive test suite (`tests/`)
15-
16-
### Key Directories
17-
- `bin/`: Build output (Debug/Release configurations)
18-
- `src/`: Main redistributable source code
19-
- `tests/`: Unit tests and integration tests
20-
- `build-tools/`: Build-time-only tooling
21-
- `external/`: Git submodules (Java.Interop, mono, etc.)
22-
- `Documentation/`: Project documentation
23-
- `eng/`: .NET Arcade SDK build infrastructure
24-
25-
### Project Types in this Repository
26-
- **Android API Bindings**: C# wrappers for Android Java APIs
27-
- **MSBuild Tasks**: Build logic for .NET Android projects
28-
- **Native Libraries**: C++ runtime components using CMake
29-
- **Java Support Code**: Java runtime classes
30-
- **Build Tools**: Custom tools for build process
31-
- **Tests**: NUnit tests, integration tests, and device tests
32-
33-
## Build System
34-
35-
This repository uses:
36-
- **MSBuild** as the primary build system with extensive `.targets` and `.props` files
37-
- **[.NET Arcade SDK](https://github.com/dotnet/arcade)** for consistent .NET build infrastructure
38-
- **CMake** for native C++ components
39-
- **Gradle** for some Android-specific build tasks
40-
41-
Common build commands:
42-
- `./build.sh` or `build.cmd` - Main build
43-
- `./dotnet-local.sh` or `dotnet-local.cmd` - Use locally built .NET tools
44-
- `make` - Various make targets for specific components
45-
46-
## Development Guidelines
47-
48-
**Always search Microsoft documentation (MS Learn) when working with .NET, Windows, or Microsoft features, APIs, or integrations.** Use the `microsoft_docs_search` tool to find the most current and authoritative information about capabilities, best practices, and implementation patterns before making changes.
49-
50-
## Localization Files
51-
52-
**DO NOT modify localization files that are automatically maintained by bots and build integrations:**
53-
54-
- **Never modify `*.lcl` files** in the `Localize/loc/` directory - these are managed by localization automation
55-
- **Never modify non-English `*.resx` files** (e.g., `Resources.ja.resx`, `Resources.ko.resx`, etc.) - these are auto-generated from the main English resources
56-
- **Only modify the main English `*.resx` files** (e.g., `Resources.resx`) when updating user-facing strings
57-
- The localization bots will automatically update all translated versions based on changes to the main English resources
58-
59-
When making changes to user-facing text:
60-
1. Only update the main English `*.resx` files
61-
2. Let the automated systems handle all translations and localized files
62-
3. Do not manually edit translated content as it will be overwritten
63-
64-
## Android Development Patterns
65-
66-
### API Bindings
67-
- Android Java APIs are bound to C# in `src/Mono.Android/`
68-
- Follow existing patterns for Android namespaces (e.g., `Android.App`, `Android.Content`)
69-
- Use `[Register]` attributes for Java type registration
70-
71-
### MSBuild Integration
72-
- Build tasks extend `Microsoft.Build.Utilities.Task` or related base classes
73-
- Place custom MSBuild logic in `src/Xamarin.Android.Build.Tasks/Tasks/`
74-
- Follow existing error code patterns (e.g., `XA####` for errors, `XA####` for warnings)
75-
- Support incremental builds where possible
76-
- Follow patterns in [`Documentation/guides/MSBuildBestPractices.md`](Documentation/guides/MSBuildBestPractices.md)
77-
78-
### Native Code
79-
- C++ code uses CMake build system
80-
- Native libraries are in `src/native/`
81-
- Follow Android NDK patterns and conventions
82-
- Use proper JNI patterns for Java interop
83-
84-
### Testing Patterns
85-
- Unit tests go in `tests/` directory
86-
- Device integration tests in `tests/MSBuildDeviceIntegration/`
87-
- Use NUnit for C# tests
88-
- Mock Android APIs appropriately for unit testing
89-
- Follow patterns in [`Documentation/workflow/UnitTests.md`](Documentation/workflow/UnitTests.md) for comprehensive testing guidance
90-
91-
### Development and Debugging
92-
- Use `MSBUILDDEBUGONSTART=2` environment variable to debug MSBuild tasks
93-
- Follow patterns in [`Documentation/workflow/DevelopmentTips.md`](Documentation/workflow/DevelopmentTips.md)
94-
- Use update directories for rapid testing of Debug builds on devices
95-
- Utilize `dotnet test --filter` for running specific unit tests
96-
- Reference [`Documentation/workflow/MSBuildBestPractices.md`](Documentation/workflow/MSBuildBestPractices.md) for MSBuild debugging techniques
3+
**.NET for Android** (formerly Xamarin.Android) - Open-source Android development bindings for .NET languages. `main` branch targets **.NET 10**.
4+
5+
## Architecture
6+
- `src/Mono.Android/` - Android SDK bindings in C#
7+
- `src/Xamarin.Android.Build.Tasks/` - MSBuild tasks for Android apps
8+
- `src/native/` - Native runtime (MonoVM/CoreCLR/NativeAOT)
9+
- `external/Java.Interop/` - JNI bindings and Java-to-.NET interop
10+
- `tests/` - NUnit tests, integration tests, device tests
11+
12+
**Build System:** MSBuild + .NET Arcade SDK + CMake (native)
13+
14+
## Essential Commands
15+
- **Build:** `./build.sh` or `build.cmd`
16+
- **Test with local build:** `dotnet-local.sh`/`dotnet-local.cmd`
17+
- **Run tests:** `dotnet-local.cmd test bin/TestDebug/net9.0/Xamarin.Android.Build.Tests.dll --filter Name~TestName`
18+
- **Device tests:** `dotnet-local.cmd test bin/TestDebug/MSBuildDeviceIntegration/net9.0/MSBuildDeviceIntegration.dll`
19+
20+
## Critical Rules
21+
22+
**Only modify the main English `*.resx` files** (e.g., `Resources.resx`)
23+
24+
**Never modify non-English localization files:** `*.lcl` files in `Localize/loc/` or non-English `*.resx` files are auto-generated.
25+
26+
**Use Microsoft docs:** Search MS Learn before making .NET, Windows, or Microsoft features, APIs, or integrations. Use the `microsoft_docs_search` tool.
27+
28+
**MSBuild Tasks:** Extend `AndroidTask` base class, use `XA####` error codes, test in isolation.
29+
30+
**API Bindings:** Use `[Register]` attributes, follow `Android.*` namespace patterns.
31+
32+
**Native Code:** Use CMake, handle multiple ABIs (arm64-v8a, armeabi-v7a, x86_64, x86).
9733

9834
## Nullable Reference Types
9935

@@ -187,23 +123,11 @@ if (!UncompressedFileExtensions.IsNullOrWhiteSpace ()) {
187123

188124
## Formatting
189125

190-
C# code uses tabs (not spaces) and the Mono code-formatting style defined in `.editorconfig`
191-
192-
* Your mission is to make diffs as absolutely as small as possible, preserving existing code formatting.
193-
194-
* If you encounter additional spaces or formatting within existing code blocks, LEAVE THEM AS-IS.
195-
196-
* If you encounter code comments, LEAVE THEM AS-IS.
197-
198-
* Place a space prior to any parentheses `(` or `[`
199-
200-
* Use `""` for empty string and *not* `string.Empty`
201-
202-
* Use `[]` for empty arrays and *not* `Array.Empty<T>()`
203-
204-
* Do *NOT* leave random empty lines when removing code.
205-
206-
Examples of properly formatted code:
126+
C# code uses tabs (not spaces) and Mono style (`.editorconfig`):
127+
- Preserve existing formatting and comments
128+
- Space before `(` and `[`: `Foo ()`, `array [0]`
129+
- Use `""` not `string.Empty`, `[]` not `Array.Empty<T>()`
130+
- Minimal diffs - don't leave random empty lines
207131

208132
```csharp
209133
Foo ();
@@ -221,99 +145,25 @@ try {
221145
}
222146
```
223147

224-
## Error and Warning Patterns
225-
226-
### Error Codes
227-
- Use `XA####` for MSBuild errors (e.g., `XA1234`)
228-
- Use `XA####` for MSBuild warnings
229-
- Use `APT####` for Android Asset Packaging Tool errors
230-
- Include clear, actionable error messages
231-
- Reference documentation when available
232-
233-
### Logging
234-
- Use MSBuild logging (`Log.LogError`, `Log.LogWarning`, `Log.LogMessage`)
235-
- Every `LogCodedWarning` and `LogCodedError` needs an error/warning code
236-
- Include relevant context (file paths, line numbers when available)
237-
- Make error messages helpful for developers
238-
239-
## Documentation Patterns
148+
## Error Patterns
149+
- **MSBuild Errors:** `XA####` (errors), `XA####` (warnings), `APT####` (Android tools)
150+
- **Logging:** Use `Log.LogError`, `Log.LogWarning` with error codes and context
240151

241-
### Code Documentation
242-
- Use XML documentation comments for public APIs
243-
- Document Android API level requirements where relevant
244-
- Include `<example>` tags for complex APIs
245-
- Reference official Android documentation where helpful:
246-
- [Android Developer Guide](https://developer.android.com/develop)
247-
- [Android API Reference](https://developer.android.com/reference)
248-
249-
### Project Documentation
250-
- Update relevant `.md` files in `Documentation/` when making significant changes
251-
- Follow existing documentation structure and formatting
252-
- Include code examples that actually work
253-
254-
## Commit Message Guidelines
255-
256-
Follow the patterns in `Documentation/workflow/commit-messages.md`:
257-
258-
### Summary Format
152+
## Commit Format
259153
```
260154
[Component] Summary
261155
```
156+
Components: `[Mono.Android]`, `[Build.Tasks]`, `build`, `ci`, `docs`, `tests`
262157

263-
Where Component is either:
264-
- Directory name (e.g., `[Mono.Android]`, `[Build.Tasks]`)
265-
- Broad category: `build`, `ci`, `docs`, `tests`
266-
267-
### Dependency Bumps
268158
```
269159
Bump to org/repo/branch@commit
270160
Bump to [Dependency Name] [Dependency Version]
271161
```
272162

273-
### Required Sections
274-
- **Changes**: What was modified
275-
- **Fixes**: Issues resolved (include GitHub issue numbers)
276-
- **Context**: Why the change was needed
277-
278-
## Common Troubleshooting
279-
280-
### Build Issues
281-
- Clean `bin/` and `obj/` directories
282-
- Ensure Android SDK/NDK are properly configured
283-
- Use `make clean` for complete rebuild
284-
285-
### MSBuild Task Development
286-
- Test tasks in isolation first
287-
- Handle incremental build scenarios
288-
- Consider cross-platform compatibility (Windows/macOS/Linux)
289-
- Validate inputs and provide clear error messages
290-
- Use `MSBUILDDEBUGONSTART=2` for debugging MSBuild tasks
291-
292-
### Device Testing
293-
- Use `tests/MSBuildDeviceIntegration/` for comprehensive device tests
294-
- Leverage update directories for rapid iteration on Debug builds
295-
- Use `dotnet test --filter` to run specific tests
296-
- Ensure proper Android emulator/device setup for testing
297-
298-
### Performance and Diagnostics
299-
- Use profiling capabilities documented in [`Documentation/guides/profiling.md`](Documentation/guides/profiling.md)
300-
- Leverage tracing features documented in [`Documentation/guides/tracing.md`](Documentation/guides/tracing.md)
301-
- Monitor build performance and optimize accordingly
302-
303-
### Native Development
304-
- Use appropriate CMake patterns from existing code
305-
- Handle different Android ABIs (arm64-v8a, armeabi-v7a, x86_64, x86)
306-
- Note: Native CoreCLR components in `src/native/clr` only target 64-bit platforms (arm64-v8a, x86_64)
307-
- Follow Android NDK security best practices
308-
- Test on multiple Android API levels when relevant
309-
310-
### Android API Management
311-
- Follow [`Documentation/workflow/HowToAddNewApiLevel.md`](Documentation/workflow/HowToAddNewApiLevel.md) for adding new Android API levels
312-
- Use existing patterns for Java-to-C# API bindings
313-
- Understand Android backward/forward compatibility requirements
314-
315-
## Contributing Guidelines
316-
317-
### Updating AI Instructions
318-
- Always update `copilot-instructions.md` when making changes that would affect how AI assistants should work with the codebase
319-
- This includes new patterns, conventions, build processes, or significant structural changes
163+
Required sections: **Changes**, **Fixes** (#issue-numbers), **Context**
164+
165+
## Troubleshooting
166+
- **Build:** Clean `bin/`+`obj/`, check Android SDK/NDK, `make clean`
167+
- **MSBuild:** Test in isolation, validate inputs
168+
- **Device:** Use update directories for rapid Debug iteration
169+
- **Performance:** See `../Documentation/guides/profiling.md` and `../Documentation/guides/tracing.md`

0 commit comments

Comments
 (0)