简体   繁体   中英

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?

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.

    解决方案结构

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

在此输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM