VSProject2.Imports VSProject2.Imports VSProject2.Imports VSProject2.Imports Property


Gets the Imports object associated with the project. For C# projects, the Imports property is set to Nothing (a null reference).

 property VSLangProj::Imports ^ Imports { VSLangProj::Imports ^ get(); };
[get: System.Runtime.InteropServices.DispId(11)]
public VSLangProj.Imports Imports { get; }
member this.Imports : VSLangProj.Imports
Public ReadOnly Property Imports As Imports
Property Value

An Imports collection, each item representing an import statement.



To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples. Open a Visual Basic project before running this example.

[Visual Basic]

' Add-in  
Imports VSLangProj  
Imports VSLangProj80  

Public Sub OnConnection(ByVal application As Object, ByVal connectMode _  
 As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) _  
 Implements IDTExtensibility2.OnConnection  
    applicationObject = CType(application, DTE2)  
    addInInstance = CType(addInInst, AddIn)  
End Sub  

Sub ListImports(ByVal dte As DTE2)  
    ' The first project is a Visual Basic or C# project.  
    Dim vsproject As VSProject2 = _  

    Dim projImports As VSLangProj.Imports = vsproject.Imports  
        ' For C# projects, projImports will be Nothing.  
    If Not (projImports Is Nothing) Then  
        Dim i As Integer  
        Dim str As String  
        str = ""  
        For i = 1 To projImports.Count  
            str = (str & str.Concat(projImports.Item(i)) & vbCrLf)  
        MsgBox("This project has no imports.")  
    End If  
End Sub  


using System.Windows.Forms;  
using VSLangProj;  
using VSLangProj2;  
using VSLangProj80;  
public void OnConnection(object application, ext_ConnectMode  
 connectMode, object addInInst, ref Array custom)  
    applicationObject = (DTE2)application;  
    addInInstance = (AddIn)addInInst;  
public void ListImports( DTE2 dte )   
// The first project is a Visual Basic or C# project.  
    VSProject2 vsproject = ( ( VSProject2 )  
(applicationObject.Solution.Projects.Item( 1 ).Object ) );   
    VSLangProj.Imports projImports = vsproject.Imports;   
    // For C# projects, projImports will be Nothing.  
    if ( !(  projImports == null ))   
        int i = 0;   
        string str = null;   
        string str1 = projImports.Count.ToString();  
        MessageBox.Show("The number of Imports is: " + str1);   
        MessageBox.Show( projImports.ContainingProject.Name );   
        str = "";   
        for ( i=1; i<=projImports.Count; i++ )   
            str = ( str + String.Concat( projImports.Item( i ) )  
 + "
" ); } MessageBox.Show( str); } else { MessageBox.Show( "This project has no imports."); } }


C# projects do not have project imports. For C# projects, the value of Imports is Nothing (a null reference).

Applies to