views:

72

answers:

2

I am building a library in Visual Studio, and I have decided on my namespace structure as CompanyName.Type.Action e.g. MyCompany.Common.DataFile.

In Visual Studio I accomplish this by creating a new solution with name MyCompany.Common and then adding to the MyCompany.Common project the class DataFile.

First of all, this leads to the solution and the project having the same name, which I don't think is best practice.

Second, I would end up with a lot of files in the MyCompany.Common project, instead of a lot of projects in the MyCompany.Common solution.

I could rename the solution to MyCompany and then have a project called Common, but I would still have a lot of files related to Common inside a single project.

Is this the best way of doing libraries? How do you guys go about it?

+1  A: 

It depends if you're going to have any other projects within the solution. The solution name really doesn't matter - most of the time, the solution is just a container for projects. You can have the same project in multiple solutions perfectly easily.

Your project should definitely be MyCompany.Common rather than just Common, IMO. Don't forget that the name of the generated assembly and default namespace are defaulted to be the same as the project name.

Jon Skeet
VinayC
It would appear that using directories inside the project is a pretty good way of doing things as the namespace inherits the directory name.
lejon
+1  A: 

Unless you need to split up your code in several projects I would recommend you avoid this. The reason is that compiling a solution with many projects take much longer than a solution with few projects, and that having lots of dll-files may be confusing to whoever will use your library.

Now for what you are doing I would suggest naming the solution so that you know what is in it. For each project you can set the default namespace to whatever you need, so even if your solution is called MyCompanyLibrary your project have have a default namespace like MyCompany.Common.
In addition you can override the suggested namespace for any file in your project, so you don't have to follow the suggested structure if you don't want to. As long as your structure is clean and understandable you should be fine.

Rune Grimstad