Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About the leading newline in Visual Studio solution files

Sometimes, for unknown reasons, VS 2008 creates solution files led by a newline.


Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
[...]

This happened on various machines, and I have no idea why this is. A Google search did not yield any useful results.

Now, why do I worry about this? Because I can't open these solutions in Windows Explorer. I have to open VS, select File -> Open -> Solution and it works fine. But to open solutions from within Explorer, I have to edit the sln file and remove the leading newline.

Edit: After Leom's suggestion I tested a few times and found that the issue is solely dependent on the leading newline.

Edit: Interesting: VS 2010 displays the same behavior the other way around: It only works with a leading newline! At least on some solutions - on other solutions it's exactly the same as with VS 2008. I'm confused.

like image 515
mafu Avatar asked Mar 18 '10 12:03

mafu


3 Answers

I too have observed strange behaviour regarding opening .sln file from explorer.

  • If you save the solution file as UTF-8 or Unicode, start the .sln file with an empty line. Otherwise it will not open when double clicking.
  • If you save the solution file as ANSI, don't start the .sln file with an empty line. Otherwise it will not open when double clicking.

It seems the Visual Studio Version Selector doesn't trust the BOM and wants a leading new line, unless the file is in ANSI encoding, than the leading new line must be omitted.

You can see this yourself when doing a save as on the solution file and selecting a different encoding.

Could be some legacy stuff.

like image 148
The_Fox Avatar answered Sep 19 '22 12:09

The_Fox


I too faced the same issue. I observed this scenario after doing a reverse merge using IBM rational clearcase. It introduced a blank line at the beginning of the ".sln" file during reverse merge. To resolve this I opened the sln file in an editor (i used VI) and removed the blank line and saved the file. Then the file opened up in visual studio with a double click.

like image 36
MUSTAQ Avatar answered Sep 19 '22 12:09

MUSTAQ


I too have a blank line in my solution files, but I do not have this issue.

I did some digging, it appears that solution files actually launch the Visual Studio Version Selector, and the first 2 lines (not sure if it the actual first 2 lines, or the first 2 lines of text) of the .sln file act as the input parameters for this selector.

There could have been a possible corruption of this executable.

In addition, you may try in Visual Studio Tools->Options->Environment->General and choose the "Restore File Assoications".

like image 39
gooch Avatar answered Sep 20 '22 12:09

gooch