Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

VB.NET Imports

What is the difference (if any) between importing namespaces at the project level vice using the Imports statement in individual classes?  My gut tells me to scope things as low as possible, but that practice is proving tedious in my current project. 

What is everybody else doing?  Are there performance or maintainability issues with either approach?

Joe Paradise
Tuesday, June 24, 2003

First, I don't know anything about VB.NET.

In C#, "importing" at the project or compiler level refers to ASSEMBLIES. This tells the compiler to look at an assembly and see if it might have one of those funny types you're referencing.  It doesn't have any influence on how you write your code.

Using the "using" statement in a program -- which I gather is the equivalent of "import" in VB.NET -- refers to NAMESPACES. This allows you to use abbreviations, so that you can write Rectangle instead of System.Drawing.Rectangle.

The compiler will not know where to take System.Drawing.Rectangle from unless you import the System.Drawing assembly. The compiler will not know that Rectangle refers to System.Drawing.Rectangle unless you import/use the System.Drawing namespace.

In C#, there is no drawback to the "using" statement as the compiler will always complain when a name is ambiguous. VB.NET should do the same, I think.

Chris Nahr
Tuesday, June 24, 2003

From my limited understanding, if you are always going to be building your project from the VS.NET IDE, project level imports are the way to go. 

If you are going to do command line or automated builds, then you are better off doing imports in each class.

Check out the Wednesday, April 23 2003 rant from Mr. AngryCoder:

Jason Watts
Tuesday, June 24, 2003

Chris:  I don't know anything about C#, but I think "using" is equivalent to "Imports".  VB.NET does flag unknown or ambiguous names.

Jason:  Excellent link.  I'm using an automated build program that goes through the IDE, so project level imports should work.

Thanks a million.

Joe Paradise
Tuesday, June 24, 2003


What autmated build program are you using?

I'm looking into automated builds for VB.Net programs (using Visual Studio 2003) and any suggestions as to the appropriate tools are very helpful.


Himanshu Nath
Tuesday, June 24, 2003

The two leaders (that I know of) are FinalBuilder by AtoZed Software and Visual Build by Kinook Software:

If you search the main JoS board you'll find several threads on this subject, including this one where I tore into FinalBuilder:

I was underwhelmed with FinalBuilder because of the gotchas I described in the thread and the author's response to my complaints.  Determined to switch, I tried a demo of Visual Build Pro 5.0, but liked it even less!

So to answer your original question, I use FinalBuilder (code projects are VB.NET).  When I switched from VS.NET 2002 to VS.NET 2003, I "refactored" my build scripts and was able to work around _some_ of the issues I had.

Be sure to try both before you buy!

Joe Paradise
Tuesday, June 24, 2003

*  Recent Topics

*  Fog Creek Home