Imports::Add Method (String^)
Visual Studio 2015
Adds a new import statement to the Imports collection.
Assembly: VSLangProj (in VSLangProj.dll)
Parameters
- bstrImport
-
Type:
System::String^
Required. The import statement string. The format of an import string is:
[alias = ]namespace[.*]
Items enclosed in square brackets are optional.
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.
' 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
Show: