Is it a best practice to commit a .sln file to source control? When is it appropriate or inappropriate to do so?

Update There were several good points made in the answers. Thanks for the responses!


Solution 1:

I think it's clear from the other answers that solution files are useful and should be committed, even if they're not used for official builds. They're handy to have for anyone using Visual Studio features like Go To Definition/Declaration.

By default, they don't contain absolute paths or any other machine-specific artifacts. (Unfortunately, some add-in tools don't properly maintain this property, for instance, AMD CodeAnalyst.) If you're careful to use relative paths in your project files (both C++ and C#), they'll be machine-independent too.

Probably the more useful question is: what files should you exclude? Here's the content of my .gitignore file for my VS 2008 projects:

*.suo
*.user
*.ncb
Debug/
Release/
CodeAnalyst/

(The last entry is just for the AMD CodeAnalyst profiler.)

For VS 2010, you should also exclude the following:

ipch/
*.sdf
*.opensdf

Solution 2:

Yes -- I think it's always appropriate. User specific settings are in other files.

Solution 3:

Yes you should do this. A solution file contains only information about the overall structure of your solution. The information is global to the solution and is likely common to all developers in your project.

It doesn't contain any user specific settings.

Solution 4:

You should definitely have it. Beside the reasons other people mentioned, it's needed to make one step build of the whole projects possible.

Solution 5:

I generally agree that solution files should be checked in, however, at the company I work for we have done something different. We have a fairly large repository and developers work on different parts of the system from time to time. To support the way we work we would either have one big solution file or several smaller. Both of these have a few shortcomings and require manual work on the developers part. To avoid this, we have made a plug-in that handles all that.

The plug-in let each developer check out a subset of the source tree to work on simply by selecting the relevant projects from the repository. The plugin then generates a solution file and modifies project files on the fly for the given solution. It also handles references. In other words, all the developer has to do is to select the appropriate projects and then the necessary files are generated/modified. This also allows us to customize various other settings to ensure company standards.

Additionally we use the plug-in to support various check-in policies, which generally prevents users from submitting faulty/non-compliant code to the repository.