Imports.Add Method
Adds a new import statement to the Imports collection.
Namespace: VSLangProj
Assembly: VSLangProj (in VSLangProj.dll)
Syntax
'Declaration
Sub Add ( _
bstrImport As String _
)
void Add(
string bstrImport
)
void Add(
[InAttribute] String^ bstrImport
)
abstract Add :
bstrImport:string -> unit
function Add(
bstrImport : String
)
Parameters
bstrImport
Type: StringRequired. The import statement string. The format of an import string is:
[alias = ]namespace[.*]
Items enclosed in square brackets are optional.
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.
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
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.