Chapter 5: Creating and Building Projects | 123 |
Assembly references are added to a project to tell the compiler where to find the types it is using in an application. When your compiler runs, it will know what types you have in your code and looks through the set of referenced assemblies to find that type. Adding an assembly reference doesn’t add all of the code from the referenced assembly to your code; it just tells the compiler where to look.
NOTE
There is often confusion around the relationship between assembly references and namespaces. A namespace using statement (Imports in VB) allows your code to be written without fully qualifying type references for types in an assembly. However, the assembly reference is just a way to tell the compiler in which specific external assembly to look to find those types: two different purposes. This confusion is exacerbated by the fact that you get the same error message from the compiler when you either are missing an assembly reference or don’t have a using (Imports for VB) directive in your code for a namespace that a type resides in. Just remember to ensure that you have an assembly reference first and then add a using (Imports) directive at the top of your file.
Adding a .NET Assembly Reference
You can add references to your project by