Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

VSProject2.Imports Property 

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

Namespace: VSLangProj80
Assembly: VSLangProj80 (in vslangproj80.dll)

Imports Imports { get; }
/** @property */
Imports get_Imports ()

function get Imports () : Imports

Property Value

An Imports collection, each item representing an import statement.

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

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.

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 ) )
 + "\n" ); 
        MessageBox.Show( str); 
        MessageBox.Show( "This project has no imports."); 
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.