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
CsWin32 comes with dependencies on Windows metadata for the SDK and WDK, allowing C# programs to generate interop code for Windows applications.
4
+
But the general transformation from metadata to C# code may be applied to other metadata inputs, allowing you to generate similar metadata for 3rd party native libraries and use CsWin32 to generate C# interop APIs for it.
5
+
6
+
## Constructing metadata for other libraries
7
+
8
+
Constructing metadata is outside the scope of this document.
9
+
However you may find [the win32metadata architecture](https://github.com/microsoft/win32metadata/blob/main/docs/architecture.md) document instructive.
10
+
11
+
## Hooking metadata into CsWin32
12
+
13
+
Metadata is fed into CsWin32 through MSBuild items.
14
+
15
+
Item Type | Purpose
16
+
--|--
17
+
`ProjectionMetadataWinmd` | Path to the .winmd file.
18
+
`ProjectionDocs` | Path to an optional msgpack data file that contains API-level documentation.
19
+
`AppLocalAllowedLibraries` | The filename (including extension) of a native library that is allowed to ship in the app directory (as opposed to only %windir%\system32).
20
+
21
+
## Packaging up metadata
22
+
23
+
Build a NuGet package with the following layout:
24
+
25
+
```
26
+
buildTransitive\
27
+
YourPackageId.props
28
+
yournativelib.winmd
29
+
runtimes\
30
+
win-x86\
31
+
yournativelib.dll
32
+
win-x64\
33
+
yournativelib.dll
34
+
win-arm64\
35
+
yournativelib.dll
36
+
...
37
+
```
38
+
39
+
Your package metadata may want to express a dependency on the Microsoft.Windows.CsWin32 package.
40
+
41
+
The `YourPackageId.props` file should include the msbuild items above, as appropriate.
A project can reference your NuGet package to get both the native dll deployed with their app and the C# interop APIs generated as they require through NativeMethods.txt using CsWin32, just like they can for Win32 APIs.
0 commit comments