If you create a Visual Basic code snippet, you have the ability to
specify the necessary references and Imports
statements required for your code to run. When the code snippet is
inserted, Visual Studio 2005 will add the specified references and Imports
statements to the project. Note
|
---|
The Imports and References elements
can only be used with Visual Basic code snippets. |
Adding Imports and References These procedures
assume that you have followed the procedures explained in the How
to: Create a Basic Code Snippet topic. To specify references-
Locate the Snippet element of the
code snippet. -
Add a References element as a
child of the Snippet element. The References element is
used to group the necessary references for the code snippet. -
Add a Reference element as a child of the References
element. The Reference element specifies an individual reference.
-
Add an Assembly element as a child of the Reference
element. Make the text value of the element the name of the assembly
that you want added as a project reference. For more information, see Assembly
Element (IntelliSense Code Snippets). -
Optionally,
you can add a Url element as a child of the Reference
element. The text value of the Url element specifies a URL that
provides more information about the referenced assembly.
To specify Imports statments-
Locate the Snippet element of the
code snippet. -
Add an Imports element as a child
of the Snippet element. The Imports element is used to
group the necessary Imports statements for the code snippet. -
Add an Import element as a child of the Imports
element. The Import element specifies an individual namespace to
import. -
Add a Namespace element as a child of
the Import element. Make the text value of the element the name
of the namespace that you want to import.
Example The following code example shows a code snippet
with both the Imports and References elements. When this
code snippet is inserted, Visual Studio 2005 will add a reference to
System.Data.dll, and following line of code at the beginning of the
file: Imports System.Data
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet> <Header>
<!-- Add Header information here -->
</Header> <Snippet> <References> <Reference> <Assembly>System.Data.dll</Assembly> </Reference> </References> <Imports> <Import> <Namespace>System.Data</Namespace> </Import> </Imports>
<!-- Add rest of code snippet here -->
</Snippet> </CodeSnippet> </CodeSnippets>
|