How exactly does “Visual Studio Version Selector”

2019-01-23 02:37发布

For extensions like .sln or .csproj the default application is Microsoft Visual Studio Version Selector. I've got two versions installed, 2010 SP1 and 2012 RC. How exactly will this application decide which VS to launch?

I would say that it works like this:

  • If it finds any hint in the given file which version should be used, then it uses it. For example, at the top of .sln files there is something like this so the Version Selector can decide:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2010

  • If it doesn't find any hint it will use whichever version was later installed (in my case I reinstalled 2010 SP1 after 2012 was already installed on my PC and now I think that VS2010 is opened more often than 2012 but am not 100% sure).

This is my feeling but what are the exact rules?

2条回答
霸刀☆藐视天下
2楼-- · 2019-01-23 03:30

The .sln file must be a UTF-8-BOM file and it must start like this:

[blank line]
Microsoft Visual Studio Solution File, Format Version XX.XX[XXX...]
[description]

The [description] is for example # Visual Studio Express 2012 for Windows Desktop for VS 2012 or # Visual Studio 15 for VS 2017.

The second line is case sensitive but the third line (description) is not. If it is missing, the Selector seems to start the latest VS.

The VisualStudioVersion entry is ignored.

However, for the right file icon to be displayed, the [description] has to be exact and case sensitive.

查看更多
ら.Afraid
3楼-- · 2019-01-23 03:33

There are some version info in the file header. Otherwise it would not be possible for the file explorer to display different document icon on the .sln file with a number:

VS2008 VS2010 VS2012 VS2013 VS2015 VS2017 representing .sln files for VS versions 2008/2010/2012/2013/2015/2017

This number on the icon disappears if you edit the .sln file with notepad or some other text editor that does not preserve the UTF-8 signature (see comment by Paul Groke). In this case also the version selector cannot choose the right version, and you cannot open it from the file explorer. You can specifically open it from within Visual Studio and save the .sln file to fix it. Also see this for more on this issue.

查看更多
登录 后发表回答