views:

1580

answers:

15

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!

+47  A: 

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

Lou Franco
DefinitelyThe .sln has references to the .prj files (projects)
dplante
+15  A: 

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.

JaredPar
+2  A: 

Yes, you always want to include the .sln file, it includes the links to all the projects that are in the solution.

Josh W.
+2  A: 

We do because it keeps everything in sync. All the necessary projects are located together, and no one has to worry about missing one. Our build server (Ant Hill Pro) also uses the sln to figure which projects to build for a release.

Kevin
A: 

.slns are the only thing we haven't had problems with in tfs!

brian b
That's funny... SLNs were the only files I have ever had to fix... but the problems were caused by devs not being careful with merges.
Matthew Whited
+5  A: 

Yes, it should be part of the source control. When ever you add/remove projects from your application, .sln would get updated and it would be good to have it under source control. It would allow you to pull out your application code 2 versions back and directly do a build (if at all required).

Andriyev
+12  A: 

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

Mehrdad Afshari
+5  A: 

Yes, things you should commit are:

  • solution (*.sln),
  • project files,
  • all source files,
  • app config files
  • build scripts

Things you should not commit are:

  • solution user options (.suo) files,
  • build generated files (e.g. using a build script) [Edit:] - only if all necessary build scripts and tools are available under version control (to ensure builds are authentic in cvs history)

Regarding other automatically generated files, there is a separate thread.

Groo
I have to disagree with "any automatically generated file."
Mehrdad Afshari
@Mehrdad do you think the Intelisense files should be commited too?
Edison Gustavo Muenz
@Edison: Nope. I'm referring to auto generated source files like LINQ to SQL data context, for instance.
Mehrdad Afshari
http://stackoverflow.com/questions/893913/should-i-store-generated-code-in-source-control
Mehrdad Afshari
Aren't Formname.Designer.cs files considered automatically generated?
jasonh
Perhaps he means "build generated files". For example, with Qt, you should not commit the moc generated source files.
sean e
Likewise there are some source files generated by the midl compiler that generally should not be committed. The input files should be committed, but the output files, not.
sean e
What I meant were files generated during build time. I find this often - someone commits a file which is built automatically, and then SVN reports a change just because some comment was changed.
Groo
When I work with tools such as SandCastle I even check in the XML comment files. But I normally target these to a document directory instead of the bin.
Matthew Whited
Sometimes it makes sense to commit generated files, for instance when they take a long time to generate.
Makach
@Makach - good point, we did find this annoying, but then we changed tools to act differently depending of the build configuration. To speed up Debug builds, tool only rebuilds files if necessary (e.g. only if they don't exist, on depending on the specific rule for that file). This also speeds up overall build because VS doesn't have to rebuild assemblies where no files have been changed. In Release build config, we always rebuild them. The simplest case (in debug mode, rebuild only if file doesn't exist) is pretty simple to implement.
Groo
+1  A: 

The only case where you would even considder not storing it in source control would be if you had a large solution with many projects which was in source control, and you wanted to create a small solution with some of the projects from the main solution for some private transient requirement.

Joe
+1  A: 

Yes - Everything used to generate your product should be in source control.

Michael
+6  A: 

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.

Brian Rasmussen
Sounds like this might be the answer to one of my long-unanswered questions (http://stackoverflow.com/questions/1490728/what-are-the-advantages-of-having-projects-in-the-same-solution-if-you-use-file-r), any chance of getting hold of a copy of this plugin?
Benjol
@Benjol: Sorry, no it is an internal tool. In addition to the features above it also integrates with a number of other internal systems, so it is very specific to how we run things. If you only need the solution/project part of things it is not that hard to implement.
Brian Rasmussen
OK, just one thing, in your 'big solution' do you have project references or file references? And if a developer adds a new reference to a file/project, does the plugin do the appropriate conversion back before checking in? And how do you handle the dependencies which the developer hasn't chosen to checkout?
Benjol
+1  A: 

We keep or solution files in TFS Version Control. But since or main solution is really large, most developers have a personal solution containing only what they need. The main solution file is mostly used by the build server.

Sylvain
A: 

1) Create a new project in VS
2) Right click on the solution in Solution Explorer, select Add to Source Control

Is the sln added to source control? That's your answer.

Will
Did you read the question?
jlembke
This answer is well worth using reputation to downvote.
The Matt
Is it a best practice to put it into source control? The people who invented the ******* thing apparently seem to think so (as my answer would demonstrate), which answers the question completely.
Will
you are obviously passionate about... sln files...
jlembke
They are... my life.
Will
+1  A: 

We usually put all of our solutions files in a solutions directory. This way we separate the solution from the code a little bit, and it's easier to pick out the project I need to work on.

MayorAwesome
+22  A: 

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
Trevor Robinson
I also have an ignore rule for Unit test results. Some people might check them in but I don't like the clutter
Matthew Whited
+1 - I personally also don't commit anything that gets built, thus bin/ and obj/
SnOrfus
I only commit .sln files that contain more than 1 project
Kragen
here is my subversion Global ignore patter: *.vsmdi *.suo */[Bb]in [Bb]in */obj obj TestResults *.[Uu]ser *Thumbs.db *Web.Publish.xml *WebApplication.Publish.xml *Web.log
Merritt