แก้ไข

แชร์ผ่าน


Compiling an Interop Project

COM interop projects that reference one or more assemblies containing imported COM types are compiled like any other managed project. You can reference interop assemblies in a development environment such as Visual Studio, or you can reference them when you use a command-line compiler. In either case, to compile properly, the interop assembly must be in the same directory as the other project files.

There are two ways to reference interop assemblies:

  • Embedded interop types: Beginning with the .NET Framework 4 and Visual Studio 2010, you can instruct the compiler to embed type information from an interop assembly into your executable. This is the recommended technique.

  • Deploying interop assemblies: You can create a standard reference to an interop assembly. In this case, the interop assembly must be deployed with your application.

The differences between these two techniques are discussed in greater detail in Using COM Types in Managed Code.

Embedding interop types with Visual Studio is demonstrated in Walkthrough: Embedding Types from Managed Assemblies in Visual Studio.

To reference an interop assembly with a command-line compiler and embed type information in your executables, use the -link (C# Compiler Options) or the -link (Visual Basic) compiler switch and specify the name of the interop assembly.

Note

Visual C++ applications cannot embed type information, but they can interoperate with applications or add-ins that do.

To compile an application that includes a primary interop assembly when it is deployed, use the /reference compiler switch and specify the name of the interop assembly.

See also