[msbuild] Add an EnableCrashReport property to enable .NET crash reports. Fixes #26130#26134
Conversation
Add a new 'EnableCrashReport' MSBuild property that, when set to true, sets the DOTNET_EnableCrashReport=1 environment variable at app startup. This makes the .NET runtime write a crash report when the app crashes. The environment variable is emitted as a setenv () call in the generated xamarin_setup_impl, which runs before CoreCLR is loaded. Also gate xamarin_initialize_crash_report_directory on DOTNET_EnableCrashReport, so DOTNET_CrashReportRootPath is only set when crash reports are enabled. Fixes #26130 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Verify that building with EnableCrashReport=true makes the generated native main set the DOTNET_EnableCrashReport environment variable at startup, and that it's not set otherwise. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…CrashReport Rework the EnableCrashReport test to actually verify a crash report is generated: build MySimpleApp with EnableCrashReport=true for macOS and Mac Catalyst, crash the app on launch (via a new CRASH_ON_LAUNCH-gated FailFast), run it, and verify that a *.crashreport.json file was created. The crash report is written by the in-proc crash reporter, which is enabled by DOTNET_EnableCrashReport=1 and writes JSON files into the directory pointed to by DOTNET_CrashReportRootPath (which the test sets to a temporary directory). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…Report Run the crashing app a second time without DOTNET_CrashReportRootPath set, to verify that the runtime's default crash report location (the app's caches directory) works too. The app is only built once per architecture; both runs reuse the same executable. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Instead of hardcoding the MySimpleApp bundle identifier, read it from the built app's Info.plist to locate the default crash report directory. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds an MSBuild-facing switch to enable .NET runtime JSON crash reports on Apple platforms by setting DOTNET_EnableCrashReport=1 at app startup, and updates runtime initialization so the crash-report root path is only configured when crash reports are enabled.
Changes:
- Add
EnableCrashReportMSBuild property support by emittingDOTNET_EnableCrashReport=1as a bundler environment variable. - Gate
DOTNET_CrashReportRootPathinitialization in the native runtime onDOTNET_EnableCrashReport=1. - Add a unit test that builds and launches a test app that crashes on startup and verifies a
*.crashreport.jsonfile is produced; document the new property.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/dotnet/UnitTests/EnableCrashReportTest.cs | Adds a new unit test validating crash report generation when EnableCrashReport=true. |
| tests/dotnet/MySimpleApp/AppDelegate.cs | Adds a test-only crash-on-launch trigger via CRASH_ON_LAUNCH=1. |
| runtime/runtime.m | Only sets DOTNET_CrashReportRootPath when DOTNET_EnableCrashReport=1 is present. |
| msbuild/Xamarin.Shared/Xamarin.Shared.targets | Wires EnableCrashReport to emit DOTNET_EnableCrashReport=1 via bundler environment variables. |
| docs/building-apps/build-properties.md | Documents the new EnableCrashReport build property and behavior. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…30-add-an-msbuild-property-that-sets-dotnet-80ed10
…orts The .NET runtime's in-process crash reporter (used on iOS, tvOS and Mac Catalyst) won't write any crash report files unless DOTNET_CrashReportRootPath points to an already-existing directory. It prints "CrashReportRootPath is not an existing directory" and writes the report to stderr instead. xamarin_initialize_crash_report_directory computed a caches subdirectory (using the bundle identifier for non-sandboxed apps) and pointed DOTNET_CrashReportRootPath at it, but never created it, so no crash report file was ever written to the default location. Create the directory before setting the environment variable, and also respect an externally-provided DOTNET_CrashReportRootPath (skip computing/creating our own directory in that case). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23087777-99bb-4141-824b-ff5f2fc17d7c
The EnableCrashReport crash report file is produced by the .NET runtime's in-process crash reporter, which is only available in the mobile CoreCLR flavor (iOS, tvOS and Mac Catalyst). The desktop macOS runtime has no in-process crash reporter (it relies on the separate 'createdump' tool, gated behind the BundleCreateDump property, which additionally requires task_for_pid entitlements that aren't available in this scenario), so it can never produce a *.crashreport.json for this property. Remove the macOS test case, which could never pass. Also clarify in the test (and the docs) that MySimpleApp isn't sandboxed, so the default crash report location is ~/Library/Caches/<bundleId> rather than the app-container caches directory a sandboxed app would use. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 23087777-99bb-4141-824b-ff5f2fc17d7c
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…30-add-an-msbuild-property-that-sets-dotnet-80ed10
✅ [CI Build #bff9400] Prepare .NET Release succeeded ✅📦 Published NuGet packages (32 packages)iOS
MacCatalyst
macOS
tvOS
Other
Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #6c5d08c] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 256 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Add a new
EnableCrashReportMSBuild property that, when set to true, sets theDOTNET_EnableCrashReport=1environment variable at app startup. This makes the .NET runtime write a JSON crash report when the app crashes.The environment variable is emitted as a
setenv ()call in the generated native main, which runs before CoreCLR is loaded. The runtime's crash-report directory initialization (xamarin_initialize_crash_report_directory) is now gated onDOTNET_EnableCrashReport, soDOTNET_CrashReportRootPathis only set when crash reports are enabled.Also adds a test (tests/dotnet/UnitTests) that builds an app with the property enabled, crashes it on launch, and verifies a crash report file is created -- both when
DOTNET_CrashReportRootPathis set to a custom location and when it's left unset (using the runtime's default caches-directory location).Documented in docs/building-apps/build-properties.md.
Fixes #26130
🤖 Pull request created by Copilot