Dela via


How to: Add References to Type Libraries

Visual Studio generates an interop assembly containing metadata when you add a reference to a type library. If a primary interop assembly is available, Visual Studio uses the existing assembly before generating a new interop assembly.

To add a reference to a type library in Visual Studio

  1. Install the COM DLL or EXE file on your computer, unless a Windows Setup.exe file performs the installation for you.

  2. From the Project menu, select References.

  3. Select the COM tab.

  4. Select the type library from the Available References list, or browse for the .tlb file.

  5. Click OK.

  6. Right-click the newly added reference, and and then click Properties.

  7. In the Properties window, make sure that the Embed Interop Types property is set to True. This causes Visual Studio to embed type information for COM types in your executables, eliminating the need to deploy primary interop assemblies with your application.

To add a reference to a type library for command-line compilation

  1. Generate an interop assembly as described in How to: Generate Interop Assemblies from Type Libraries.

  2. Use the /link (C# Compiler Options) or /link (Visual Basic) compiler option with the interop assembly name to embed type information for COM types in your executables.

See Also

Tasks

Walkthrough: Embedding Type Information from Microsoft Office Assemblies (C# and Visual Basic)

Walkthrough: Embedding Types from Managed Assemblies (C# and Visual Basic)

Reference

/link (C# Compiler Options)

/link (Visual Basic)

Concepts

Importing a Type Library as an Assembly

Exposing COM Components to the .NET Framework