views:

56

answers:

0

Hi,

I am building an MVC2 website using VB.NET.

I had a root namespace defined for the project but blanked it out because I wanted to have full control over the namespace for each class in the project. The reason I require this control is that I define a bunch of htmlhelper extensions and want them be in the same namespace (System.Web.Mvc) so that when typing "Html." in a view I get access to these extension methods too. (BTW, this is also the way Rob Conery does it in his TekPub MVC2 series).

The problem now is that using VS to generate MVC specific code introduces compilation errors... for example, if I 'Add Area...' the namespace added to the AreaRegistration file starts with a dot. This problem also affects the 'Add Controller...' code generator (as well as others such as the add 'Domain Service Class' wizard which simply refuses to run if no root namespace is defined).

Because of these problems I had to put the root namespace back and add an import statement to all my views for the namespace containing the extension methods.

Am I missing something here? Aside from using C# or putting all extension methods in their own specific assemblies is there anything else I can do? Or am I simply not doing the right thing by trying to put extensions into the same namespace?

My gut feeling is that my requirement is reasonable and that the VB default namespace implementation used in conjunction with code generators is simply buggy because the value is passed to the VB compiler which automatically prepends it to all the classes/modules in the project without the facility to override.

What I would like is a file directive (ala imports) to clear the root namespace for this file/class only. Please someone tell me this exists!

Many thanks,

Rob.