-
Notifications
You must be signed in to change notification settings - Fork 567
Update copilot-instructions.md with learnings from recent PRs #10974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||||
| - `src/Xamarin.Android.Build.Tasks/` - MSBuild tasks for Android apps | ||||||
| - `src/native/` - Native runtime (MonoVM/CoreCLR/NativeAOT) | ||||||
| - `external/Java.Interop/` - JNI bindings and Java-to-.NET interop | ||||||
| - `external/xamarin-android-tools/` - Shared SDK tooling: `AndroidTask`/`AsyncTask` base classes, `AdbRunner`, `EmulatorRunner`, NRT extensions (`IsNullOrEmpty()`, `IsNullOrWhiteSpace()`), `CreateTaskLogger`, and SDK info utilities | ||||||
| - `tests/` - NUnit tests, integration tests, device tests | ||||||
|
|
||||||
| **Build System:** MSBuild + .NET Arcade SDK + CMake (native) | ||||||
|
|
@@ -32,7 +33,7 @@ Reference official Android documentation where helpful: | |||||
|
|
||||||
| **Use Microsoft docs:** Search MS Learn before making .NET, Windows, or Microsoft features, APIs, or integrations. Use the `microsoft_docs_search` tool. | ||||||
|
|
||||||
| **MSBuild Tasks:** Extend `AndroidTask` base class, use `XA####` error codes, test in isolation. | ||||||
| **MSBuild Tasks:** Extend `AndroidTask` base class, use `XA####` error codes, test in isolation. Use `AsyncTask` for tasks that need `async`/`await` — it handles `Yield()`, `try`/`finally`, and `Reacquire()` automatically. | ||||||
|
|
||||||
| **Internal build `<UsingTask/>` elements:** For `xa-prep-tasks` and `BootstrapTasks` (internal build-time tasks, not shipped to customers), always use `TaskFactory="TaskHostFactory"` and `Runtime="NET"` attributes on `<UsingTask/>` elements. This runs the task in a separate process to avoid Windows file locking issues and ensures the task runs on .NET (even when MSBuild.exe in Visual Studio uses .NET Framework). Example: | ||||||
|
|
||||||
|
|
@@ -57,6 +58,10 @@ When opting C# code into nullable reference types: | |||||
|
|
||||||
| * Don't *ever* use `!` (null-forgiving operator) to handle `null`! Always check for null explicitly and throw appropriate exceptions. | ||||||
|
|
||||||
| * **In test code**, avoid `!` too. Common workarounds: | ||||||
| - `[SetUp]`-initialized fields: declare as nullable (`MockBuildEngine? engine;`) instead of `MockBuildEngine engine = null!;` | ||||||
| - After `Assert.IsNotNull`: extract into a local variable (`var opts = task.Options; Assert.IsNotNull (opts); opts.Foo...`) instead of using `task.Options!.Foo` | ||||||
jonathanpeppers marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| * Declare variables non-nullable, and check for `null` at entry points. | ||||||
|
|
||||||
| * Use `throw new ArgumentNullException (nameof (parameter))` in `netstandard2.0` projects. | ||||||
|
|
@@ -181,7 +186,9 @@ This pattern ensures proper encoding, timestamps, and file attributes are handle | |||||
|
|
||||||
| ## Error Patterns | ||||||
| - **MSBuild Errors:** `XA####` (errors), `XA####` (warnings), `APT####` (Android tools) | ||||||
| - **Logging:** Use `Log.LogError`, `Log.LogWarning` with error codes and context | ||||||
| - **Error messages:** Must come from `Properties.Resources` (e.g., `Properties.Resources.XA0143`) for localization support. Add new messages to the English `Resources.resx` file. | ||||||
| - **Error code lifecycle:** When removing functionality that used an `XA####` code, either repurpose the code or remove it from `Resources.resx` and `Resources.Designer.cs`. Don't leave orphaned codes. | ||||||
jonathanpeppers marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| - **Error code lifecycle:** When removing functionality that used an `XA####` code, either repurpose the code or remove it from `Resources.resx` and `Resources.Designer.cs`. Don't leave orphaned codes. | |
| - **Error code lifecycle:** When removing functionality that used an `XA####` code, either repurpose the code or remove/rename the corresponding entry in `Resources.resx` and then regenerate `Resources.Designer.cs` (e.g., by rebuilding or running `resgen`). `Resources.Designer.cs` is auto-generated and should not be edited manually. Don't leave orphaned codes. |
Uh oh!
There was an error while loading. Please reload this page.