Imports.Add(String) Method

Definition

Adds a new import statement to the Imports collection.

public:
 void Add(System::String ^ bstrImport);
public:
 void Add(Platform::String ^ bstrImport);
void Add(std::wstring const & bstrImport);
[System.Runtime.InteropServices.DispId(5)]
public void Add (string bstrImport);
[<System.Runtime.InteropServices.DispId(5)>]
abstract member Add : string -> unit
Public Sub Add (bstrImport As String)

Parameters

bstrImport
String

Required. The import statement string. The format of an import string is:[alias = ]namespace[.*]Items enclosed in square brackets are optional.

Attributes

Examples

' Macro Editor  
Imports VSLangProj  
Public Sub AddImport()  
   ' Project must be a Visual Basic project.  
   Try  
      Dim vsproject As VSProject = _  
         CType(DTE.Solution.Projects.Item(1).Object, VSProject)  
      vsproject.Imports.Add("SomeAlias = SomeNamespace.*")  
      vsproject.Imports.Add("AnotherNamespace")  
   Catch e As System.Exception  
      MsgBox(e.Message)  
   End Try  
End Sub  

Remarks

This method generates an error if the imports statement is already in the project.

This method does not determine whether the proper references exist so that the namespace is meaningful.

To remove an imports statement, use the Remove method.

In the development environment, to check whether an import has been successfully added, choose the Properties command from the Project menu. In the left pane of the Project Property Pages dialog box, choose the Imports folder under Common Properties, and then examine the Project imports list.

Applies to