Avoid "src" in autonamatic namespace

Radim Langer 101 Reputation points
2020-12-02T08:44:39.22+00:00

Hello,
is still necessary to have "src" included in automatic namespace? I found this topic was solved years ago here:

https://social.msdn.microsoft.com/Forums/en-US/caf3a2d7-c3b4-40c6-b171-16397972de2b/how-do-i-add-a-quotsrcquot-directory-to-my-c-project-without-it-creating-a-quotsrcquot?forum=csharpide&prof=required

I understand it is not difficult to delete the src part from the generated namespace. However, I'm curious if VS2019 can do it itself.

Thank you for any comment.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,193 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,436 Reputation points
    2020-12-02T12:08:36.037+00:00

    Hello @Radim Langer

    VS2019 does not have an option to exclude the folder name e.g. if we have a namespace of Blog.Classes creating in the Class folder Operations.cs the namespace will be Blog.Classes.

    If you want Operations.cs in Blog namespace a work-around is to create Operations.cs in the root folder of the project then in solution explorer drag-n-drop the class file into a Blog.Classes.

    So your current idea and the work-around is your choice to make.

    If you have Resharper installed, right click on a folder e.g. Classes, select properties then for Namespace Provider change the value from True to False then the root namespace is used rather than appending the folder name to the namespace.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Cheong00 3,476 Reputation points
    2020-12-03T03:07:04.17+00:00

    If you really want that, you can bite the bullet and roll out your own VSWizard that will modify the $rootnamespace$ variable replace ".src." to ".".

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/da7fe34e-9c61-4d38-8018-3a71a230e15c/is-there-a-way-to-use-the-default-project-namespace-in-an-item-template-without-subfolders-which?forum=vsx

    Add a WizardData element to point to the created DLL to tell Visual Studio to use it.
    Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.Template

    Note that I've not done it myself, just expecting this to work.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.