Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices organizing a Visual Studio solution

I need some help regarding Visual Studio solution and project organization.

I have a solution with several projects. All of them are written in C# and are compiled as libraries to be used by the GUI. Some of these libraries have also dependencies with others. For example, TestExecutive needs LoggingFramework, Communications needs LoggingFramework too.

Which is the best way of organizing? I'm thinking on a folder assemblies to hold libraries' binaries in one place. Something like:

Solution
    |
    |-- TestExecutive
    |-- LoggingFramework
    |-- assemblies

There is also another problem. One of the projects uses a native C dll. Where do I have to place this library? With the librarie's assembly or with the final executable?

EDIT:

Ok, now suppose I have the WinForms program running. I have source code and binaries mixed. Which features do I need to generate something I can distribute? I mean, with all the libraries and configuration files, but without source code. I have done this before with Nullsoft installer, but I don't know if visual studio can help you doing that.

like image 299
yeyeyerman Avatar asked Aug 17 '09 13:08

yeyeyerman


2 Answers

A few things here:

  1. When one project depends on another, you can set up that dependency in Visual Studio. Right click on a project and select Project Dependencies...

  2. For other .NET assemblies that are NOT part of your solution (3rd party tools, etc.) I do exactly what you showed here -- I have a separate folder parallel to the projects. Then I set up the assembly reference in each of the projects with "Copy Local" set to true and it works fine.

  3. For native C dlls, it's a little different. There is no direct reference to them in the references section of the solution explorer. The compiler isn't going to look at the dll to check your p/invoke references or anything like that. You just need to make sure the dll is part of the deployment on your top level web or winforms project. It's a content file just like a css file or image or something. Just add it as a file in the project and make sure the "Build Action" is set to Content so Visual studio knows to just copy the file as part of the deployment

like image 133
Clyde Avatar answered Oct 19 '22 15:10

Clyde


I set my solution folders up a bit differently than you. At the top level I have the following folders:

\build
\lib
\src

The build folder has build scripts (NAnt, MSBuild, etc). Any 3rd party assemblies (or anything I'm not building in the solution) get put into the lib folder, in an appropriate sub-folder. For example, I'll have log4net, NUnit, RhinoMocks folders in the lib folder, each containing the files needed for that dependency. The src folder has the solution and all project files.

I like this structure because it clearly delineates between the project code and the other stuff that is required by the project. Also, I usually set up some custom build tasks to copy the resulting assemblies for my project into either a \deploy or \lib\ folder. This way you don't have to hunt in the \src\\bin\\ folder to get a built assembly or the whole project; however this seems a bit beyond the scope of your question.

Btw... I didn't come up with this structure on my own, I think I started off using Tree Surgeon and evolved my process from there.

like image 45
akmad Avatar answered Oct 19 '22 16:10

akmad