Skip to content

Commit db04c21

Browse files
authored
Document how to enable trimming support
#1273
1 parent ac50cb9 commit db04c21

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ CsWin32 will notice that your project already declares the type and skip generat
123123
Note that if that type is the only thing that references some other generated type, CsWin32 will stop generating that type too.
124124
To keep CsWin32 generating the referred types you need, add them explicitly to `NativeMethods.txt`.
125125

126+
### Support for trimming, AOT, and/or disabling the runtime marshaler
127+
128+
Newer .NET runtime versions may fail for CsWin32 generated code when the application project builds with one or both of these properties set:
129+
130+
```xml
131+
<PublishAot>true</PublishAot>
132+
<DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
133+
<PublishTrimmed>true</PublishTrimmed>
134+
```
135+
136+
CsWin32 supports these environments by avoiding code that relies on the runtime marshaler when the `allowMarshaling` setting is disabled in the `NativeMethods.json` file.
137+
For example:
138+
139+
```json
140+
{
141+
"$schema": "https://aka.ms/CsWin32.schema.json",
142+
"allowMarshaling": false
143+
}```
144+
126145
### Newer metadata
127146

128147
To update the metadata used as the source for code generation, you may install a newer `Microsoft.Windows.SDK.Win32Metadata` package:

0 commit comments

Comments
 (0)