How to: Generate Primary Interop Assemblies Using Tlbimp.exe
The most straightforward way to produce primary interop assemblies is to use the Type Library Importer (Tlbimp.exe).
To generate a primary interop assembly using Tlbimp.exe
At the command prompt, type:
tlbimp tlbfile **/primary /keyfile:**filename **/out:**assemblyname
In this command, tlbfile is the file containing the COM type library, filename is the name of the container or file that contains the key pair, and assemblyname is the name of the assembly to sign with a strong name.
Primary interop assemblies can reference only other primary interop assemblies. If your assembly references types from a third-party COM type library, you must obtain a primary interop assembly from the publisher before you can generate your primary interop assembly. If you are the publisher, you must generate a primary interop assembly for the dependent type library before generating the referencing primary interop assembly.
A dependent primary interop assembly with a version number that differs from that of the original type library is not discoverable when installed in the current directory. You must either register the dependent primary interop assembly in the Windows registry or use the /reference option to be sure that Tlbimp.exe finds the dependent DLL.
You can also wrap multiple versions of a type library. For instructions, see How to: Wrap Multiple Versions of Type Libraries.
Example
The following example imports the COM type library LibUtil.tlb
and signs the assembly LibUtil.dll
with a strong name using the key file CompanyA.snk
. By omitting a specific namespace name, this example produces the default namespace, LibUtil
.
tlbimp LibUtil.tlb /primary /keyfile:CompanyA.snk /out:LibUtil.dll
For a more descriptive name (using the VendorName.LibraryName naming guideline), the following example overrides the default assembly file name and namespace name.
tlbimp LibUtil.tlb /primary /keyfile:CompanyA.snk /namespace:CompanyA.LibUtil /out:CompanyA.LibUtil.dll
The following example imports MyLib.tlb
, which references CompanyA.LibUtil.dll
, and signs the assembly CompanyB.MyLib.dll
with a strong name using the key file CompanyB.snk
. The namespace, CompanyB.MyLib
, overrides the default namespace name.
tlbimp MyLib.tlb /primary /keyfile:CompanyB.snk /namespace:CompanyB.MyLib /reference:CompanyA.LibUtil.dll /out:CompanyB.MyLib.dll
See Also
Tasks
How to: Wrap Multiple Versions of Type Libraries
How to: Create Primary Interop Assemblies Manually
Concepts
Generating Primary Interop Assemblies
Producing Primary Interop Assemblies