Export (0) Print
Expand All

Imports Object

Visual Studio .NET 2003

Contains the collection of all project imports for a Visual Basic project. The import statements specified are passed directly to the compiler and apply to all the files in the project. For a description of project imports, see Imports, Common Properties, <Projectname> Property Pages Dialog Box.

[Visual Basic .NET]
Public Interface Imports
    Inherits IDispatch
[Visual Basic 6]
Class Imports
interface Imports : IDispatch
public interface Imports : IDispatch
[JScript .NET]
public interface Imports extends IDispatch


This object specifies the namespaces to import for the project. Elements from imported namespaces may be used in code without fully qualifying the name of the element. For example, if the Imports object contains the Namespace1.Namespace2 import statement, then the two following code statements are equally valid:


If the imports statement is not in the collection, then the second statement above, which is unqualified, will result in a build error.


Namespace: VSLangProj

File: VSLangProj.dll


' Macro Editor
' This routine displays all the project imports.
Imports VSLangProj
Public Sub ListImports()
   ' The first project is a Visual Basic or C# project.
   Dim vsproject As VSProject = _
      CType(DTE.Solution.Projects.Item(1).Object, VSProject)
   Dim projImports As VSLangProj.Imports = vsproject.Imports
   ' For C# projects, projImports will be Nothing.
   If Not (projImports Is Nothing) Then
      Dim i As Integer
      For i = 1 To projImports.Count
      MsgBox("This project has no imports.")
   End If
End Sub

See Also

Properties, Methods, and Events | VSLangProj Hierarchy Chart | Imports Property (VSProject Object) | Visual Basic and Visual C# Project Extensibility Examples

© 2014 Microsoft