leora
leora

Reputation: 196439

What is the best practices for directory structures in my Visual Studio project?

I have this:

SolutionName: Foo.sln

Assembly: Foo.Bar

Namespaces are:

Foo.Bar.Views
Foo.Bar.Model
Foo.Bar.BusinessObjects
Foo.Bar.Services

Should the directory structure be like this?

__Foo/Foo.Bar/Foo.Bar.View__ or __Foo/Bar/View__

Upvotes: 0

Views: 630

Answers (5)

Ariel
Ariel

Reputation: 5830

Foo/Bar/View seems a better choice, more if individual files are named as the individual types (e.g. Foo.Bar.View.IView => Foo/Bar/View/IView.cs).

That's a great pattern to follow, which makes it easier to find types, scripting over sources, do some metrics, etc.

Upvotes: 0

Patrick Johnmeyer
Patrick Johnmeyer

Reputation: 32552

This is entirely personal preference. I would choose the latter.

Ask yourself the question, "Am I adding any useful information by repeating Foo and Bar in the sub-folders?" The answer here, in my opinion, is no, simply because the information is redundant. You've also created yourself a maintenance problem; if you need to rename Bar you now have to rename Foo.Bar, Foo.Bar.View, Foo.Bar.Model ...

Upvotes: 1

aku
aku

Reputation: 123966

Foo/Bar/View seems to be natural. Also MSVS tends to map solution folders to namespaces (i.e. if you add Abc folder to your solution each class you add to this folder will be in root_namespace.Abc namespace)

Upvotes: 0

Agent_9191
Agent_9191

Reputation: 7253

If you keep the Visual Studio option of "Automatic Namespaces" you would need to have Foo/Bar/Views. Since this is the default behavior of Visual Studio people will be most used to this. Plus it keeps your folder names/paths from getting excessively long.

Upvotes: 1

casperOne
casperOne

Reputation: 74530

Well, it can be anything you wish. Either are valid, but the former might get a little redundant and lead to directory hierarchies which are a little hard on the eyes/prohibitive.

Upvotes: 0

Related Questions