You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docfx/docs/getting-started.md
+23-2Lines changed: 23 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,15 +121,36 @@ To keep CsWin32 generating the referred types you need, add them explicitly to `
121
121
122
122
### Support for trimming, AOT, and/or disabling the runtime marshaler
123
123
124
-
Newer .NET runtime versions may fail for CsWin32 generated code when the application project builds with one or both of these properties set:
124
+
**NEW!** CsWin32 now has improved support for NativeAOT by generating code from an MSBuild task rather than a source generator so that it can leverage other source generators that support `[LibraryImport]` and others.
CsWin32 supports these environments by avoiding code that relies on the runtime marshaler when the `allowMarshaling` setting is disabled in the `NativeMethods.json` file.
134
+
Then you have two options:
135
+
136
+
#### Enable CsWin32RunAsBuildTask
137
+
138
+
CsWin32 now supports AOT by generating code which relies on `GeneratedComInterface` and `LibraryImport`, which are source generators.
139
+
To make this chaining work, you have to request CsWin32 to run as a build task to generate the source code _before_ compile. Do this by adding this to your csproj:
It is also strongly recommended to set DisableRuntimeMarshalling=true as shown here to ensure that the COM source generators handle
147
+
all the marshalling correctly. See https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke-source-generation and
148
+
https://learn.microsoft.com/en-us/dotnet/standard/native-interop/comwrappers-source-generation for more information on these .NET source
149
+
generators.
150
+
151
+
#### Disable runtime marshalling
152
+
153
+
CsWin32 can also support these environments by avoiding code that relies on the runtime marshaler when the `allowMarshaling` setting is disabled in the `NativeMethods.json` file.
0 commit comments