Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Visual Studio 2015 add a new VB.NET class with a namespace declaration?

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?

like image 857
ProfK Avatar asked Oct 14 '16 17:10

ProfK


2 Answers

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

like image 188
nunzabar Avatar answered Sep 22 '22 13:09

nunzabar


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.

like image 28
Hadi Avatar answered Sep 19 '22 13:09

Hadi