From db04c21ead4eaaa62e5d0c2fd620dc571014a814 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Mon, 9 Sep 2024 09:48:15 -0600 Subject: [PATCH] Document how to enable trimming support #1273 --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index b91674a4..76beff17 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,25 @@ CsWin32 will notice that your project already declares the type and skip generat Note that if that type is the only thing that references some other generated type, CsWin32 will stop generating that type too. To keep CsWin32 generating the referred types you need, add them explicitly to `NativeMethods.txt`. +### Support for trimming, AOT, and/or disabling the runtime marshaler + +Newer .NET runtime versions may fail for CsWin32 generated code when the application project builds with one or both of these properties set: + +```xml +true +true +true +``` + +CsWin32 supports these environments by avoiding code that relies on the runtime marshaler when the `allowMarshaling` setting is disabled in the `NativeMethods.json` file. +For example: + +```json +{ + "$schema": "https://aka.ms/CsWin32.schema.json", + "allowMarshaling": false +}``` + ### Newer metadata To update the metadata used as the source for code generation, you may install a newer `Microsoft.Windows.SDK.Win32Metadata` package: