CsCom is a command line tool that produces COM interop code from type libraries or existing .NET interop assemblies, similar to TlbImp, and an MSBuild package (CsCom.Build) that generates it during the build of a project. Unlike TlbImp, it does not rely on the built-in COM interop of .NET: it generates C# code that uses the source-generated COM interop added in .NET 8, so the interop code can be trimmed and used with Native AOT. It also goes the other way, like TlbExp: it exports the type library of an assembly whose COM types are declared for source-generated COM interop.
The documentation is at cscom.fedarovich.com, starting with Getting started.
- Windows: type libraries are read with the OLE Automation APIs. Interop assemblies are read from their metadata.
- .NET 10 SDK or later. The generated projects target .NET 10 or later.
# Install the tool
dotnet tool install --global CsCom
# Generate a C# project with the interop types
cscom project create C:\Windows\System32\scrrun.dll -o Interop.Scripting
# Generate several type libraries into one project, each into its own namespace
cscom project create Excel.Application Scripting.Dictionary -n Office.Interop --ns Excel=Office.Excel
# Build a ready-to-use interop assembly, or pack it into a NuGet package
cscom assembly build C:\Windows\System32\scrrun.dll -o bin -p Version=1.0.0
cscom assembly pack C:\Windows\System32\scrrun.dll -o packages --package-version 1.0.0 -p Authors=Contoso
# List the types and members of a type library
cscom list Scripting.Dictionary --type ^IDictionary$
# Generate the interop code during the build of an existing project, with the CsCom.Build package
cscom reference add Excel.Application --namespace Office.Excel
# Export the type library of an assembly with [GeneratedComInterface] and [GeneratedComClass] types, like TlbExp
cscom typelib export bin\Release\net10.0-windows\Server.dllThe generated code:
IDictionary dictionary = Dictionary.Create(); // coclass: CoCreateInstance + ComWrappers
dictionary.CompareMode = CompareMethod.TextCompare; // C# 14 extension property over set_CompareMode
dictionary.Add("a", 1); // VARIANT parameters are object?
Console.WriteLine(dictionary.Count); // C# 14 extension property over get_Count
foreach (object? key in dictionary) // _NewEnum via IEnumVARIANT
{
}The four packages are released together, with the same version.
| Package | Description |
|---|---|
| CsCom | The cscom .NET tool: generates projects, assemblies and packages, lists type libraries, manages the CsComReference items of projects and exports type libraries. |
| CsCom.Build | The MSBuild integration, which generates the interop code during the build of a project, and can export the type library of the project. |
| CsCom.Runtime | The support code that the generated code uses: IDispatch, the marshallers, the late-bound wrappers and the events. |
| CsCom.Runtime.Dynamic | Late binding with C# dynamic. |
- Getting started and Migrating from TlbImp
- Using the tool: Sources, Commands, Interop assemblies, MSBuild integration, Exporting type libraries, Configuration file
- Generated code: marshalling, interface pointers, events,
late binding with
dynamic, support code and limitations - API reference of CsCom.Runtime and CsCom.Runtime.Dynamic
- Benchmarks against the built-in COM interop
The documentation is built from the docs folder. The changes of each version are described in
CHANGELOG.md, and the known issues that are not fixed in docs/known-issues.md.
dev is the integration branch: create feature branches from it and target pull requests to it. Building, testing and
releasing are described in Development, and the projects in
Architecture.
dotnet build src/CsCom.slnx
dotnet test src/CsCom.slnx --no-build --filter "TestCategory!=Integration"