8

Whenever I add a new VB.NET class, VS 2015 totally ignores any namespace declaration, because it's "automatically in the default namespace, but I want my classes namespaced by folder name as well. Plus I want explicit namespace declarations on all my classes.

Right now, I add a class, ReSharper squiggles it, and I elect to have it moved to the correct namespace. Is there no VS setting to always include the namespace 'wrapper' when creating a new VB.NET class?

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • 1
    Possible duplicate of [this](http://stackoverflow.com/a/3317333/386703)? – Brandon Oct 14 '16 at 18:05
  • @Brandon The answer to that question doesn't work in VS 2015. – ProfK Oct 14 '16 at 19:01
  • I was able to get it to work up to the actual name of the namespace. You can include the root namespace but nothing more. Not helpful in VB – Brandon Oct 14 '16 at 19:35
  • When I add a new class, I get `Namespace $itemfolder$`. It does no replacment at all. I tried adding the extra `WizardExtension` element to `Class.vstemplate`, I got a runtime error. I'll just code my MVVM setup in C#, and the client's form and code in VB.NET, and tell him the rest came out the box, hehe. – ProfK Oct 15 '16 at 06:47
  • That's exactly what I'd gotten too. I tried with `$rootnamespace$` but it only bought me `Namespace WindowsApplication1`. I'm kind of annoyed at this now. – Brandon Oct 15 '16 at 13:50
  • `Is there no VS setting to always include the namespace` no there is not I am afraid. Although it wont help you now, I am actually working on an extension that has this functionality... Good luck! – Trevor Oct 27 '16 at 18:07

2 Answers2

6

There's no setting for that in VS. You have to manually fight the VB framework in this case.

  1. Unload the project.
  2. Hand-edit the project file, setting RootNamespace to an empty string.

    <RootNamespace></RootNamespace>
    
  3. Reload the project and create your folder structure.

    Solution structure

Namespaces will work like C# without VS or Resharper complaining:

enter image description here

mr_plum
  • 2,448
  • 1
  • 18
  • 31
  • Why the down vote here? It didn't work for me, but I'm pretty sure it did for @nunzabar..I've offset it, so it won't show any more. – ProfK Oct 23 '16 at 19:12
1

You can only change the root namespace for a project:

1- With a project selected in Solution Explorer, on the Project menu, click Properties.

2- Click the Application tab.

3- In the Root namespace field, enter the name.

Hadi
  • 36,233
  • 13
  • 65
  • 124