Skip to content

[msbuild] Add an EnableCrashReport property to enable .NET crash reports. Fixes #26130#26134

Merged
rolfbjarne merged 9 commits into
net11.0from
dev/rolf/issue-26130-add-an-msbuild-property-that-sets-dotnet-80ed10
Jul 23, 2026
Merged

[msbuild] Add an EnableCrashReport property to enable .NET crash reports. Fixes #26130#26134
rolfbjarne merged 9 commits into
net11.0from
dev/rolf/issue-26130-add-an-msbuild-property-that-sets-dotnet-80ed10

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

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 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 on DOTNET_EnableCrashReport, so DOTNET_CrashReportRootPath is 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_CrashReportRootPath is 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

rolfbjarne and others added 5 commits July 16, 2026 15:23
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EnableCrashReport MSBuild property support by emitting DOTNET_EnableCrashReport=1 as a bundler environment variable.
  • Gate DOTNET_CrashReportRootPath initialization in the native runtime on DOTNET_EnableCrashReport=1.
  • Add a unit test that builds and launches a test app that crashes on startup and verifies a *.crashreport.json file 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.

Comment thread tests/dotnet/UnitTests/EnableCrashReportTest.cs
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 3 commits July 17, 2026 14:01
…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
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne marked this pull request as ready for review July 20, 2026 06:01
@rolfbjarne
rolfbjarne requested a review from mauroa as a code owner July 20, 2026 06:01
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

…30-add-an-msbuild-property-that-sets-dotnet-80ed10
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [CI Build #bff9400] Prepare .NET Release succeeded ✅

📦 Published NuGet packages (32 packages)

iOS

  • Microsoft.iOS.Ref.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.iOS.Runtime.ios-arm64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.iOS.Runtime.ios.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.iOS.Runtime.iossimulator-arm64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.iOS.Runtime.iossimulator-x64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.iOS.Sdk.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.iOS.Templates.26.5.11921-net11-p7.nupkg
  • Microsoft.iOS.Windows.Sdk.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.NET.Sdk.iOS.Manifest-11.0.100-preview.7.26.5.11921-net11-p7.nupkg

MacCatalyst

  • Microsoft.MacCatalyst.Ref.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.MacCatalyst.Runtime.maccatalyst-arm64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.MacCatalyst.Runtime.maccatalyst-x64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.MacCatalyst.Runtime.maccatalyst.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.MacCatalyst.Sdk.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.MacCatalyst.Templates.26.5.11921-net11-p7.nupkg
  • Microsoft.NET.Sdk.MacCatalyst.Manifest-11.0.100-preview.7.26.5.11921-net11-p7.nupkg

macOS

  • Microsoft.macOS.Ref.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.macOS.Runtime.osx-arm64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.macOS.Runtime.osx-x64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.macOS.Runtime.osx.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.macOS.Sdk.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.macOS.Templates.26.5.11921-net11-p7.nupkg
  • Microsoft.NET.Sdk.macOS.Manifest-11.0.100-preview.7.26.5.11921-net11-p7.nupkg

tvOS

  • Microsoft.NET.Sdk.tvOS.Manifest-11.0.100-preview.7.26.5.11921-net11-p7.nupkg
  • Microsoft.tvOS.Ref.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.tvOS.Runtime.tvos-arm64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.tvOS.Runtime.tvos.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.tvOS.Runtime.tvossimulator-arm64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.tvOS.Runtime.tvossimulator-x64.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.tvOS.Sdk.net11.0_26.5.26.5.11921-net11-p7.nupkg
  • Microsoft.tvOS.Templates.26.5.11921-net11-p7.nupkg

Other

  • Sharpie.Bind.Tool.26.6.0.525-net11-p7.nupkg

Pipeline on Agent
Hash: bff9400caa5c8350e81e3914dc96ef8ad69ebffc [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 6c5d08c23e57427b4dfe4217b007dde702f75637 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [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
✅ cecil: All 1 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 7 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 31 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 23 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 23 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 23 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 6c5d08c23e57427b4dfe4217b007dde702f75637 [PR build]

@rolfbjarne
rolfbjarne merged commit a04ce3e into net11.0 Jul 23, 2026
54 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/issue-26130-add-an-msbuild-property-that-sets-dotnet-80ed10 branch July 23, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an MSBuild property that sets DOTNET_EnableCrashReport=1 at startup

5 participants