Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bl-ue/4f787ddc63a4becbe928cf54586b48cd to your computer and use it in GitHub Desktop.
Save bl-ue/4f787ddc63a4becbe928cf54586b48cd to your computer and use it in GitHub Desktop.
Visual Studio solution file headers - 2002 through 2022
import re
import sys
def main():
try:
file = open(sys.argv[1])
except:
print('[[File not specified or does not exist, reading data from stdin...]]')
file = sys.stdin
lines = [l.strip() for l in file.readlines()]
file.close()
vsver2year = {
'14': '2015',
'15': '2017',
'16': '2019',
'17': '2022',
}
fmtver2year = {
'7.0': '2002',
'8.0': '2003',
'9.0': '2005',
'10.00': '2008',
'11.00': '2010',
}
fmt_ver_re = re.compile(r'^Microsoft Visual Studio Solution File, Format Version (\d+\.\d+)$')
vs_ver_re = re.compile(r'^# Visual Studio(?: Version)? (\d+)$')
fmt_ver = None
vs_ver = None
ver = None
for line in lines:
if m := fmt_ver_re.match(line):
fmt_ver, = m.groups()
# VS 2012+ always are 12.00, so there's no point in using it
if fmt_ver == '12.00':
fmt_ver = None
if m := vs_ver_re.match(line):
vs_ver, = m.groups()
if fmt_ver is not None:
ver = fmtver2year[fmt_ver]
elif vs_ver is not None:
# VS 2005-2013 (inclusive) stated the version as the year. VS 2015+ used the integer version.
if vs_ver in vsver2year:
ver = vsver2year[vs_ver]
else:
ver = vs_ver
print(f'Visual Studio {ver}')
if __name__ == '__main__':
main()
*********************************************************************************************
** Below is the header text written in the .sln files produced by Microsoft Visual Studio. **
** By default, each header is preceeded by a Windows new line character (CRLF) in the .sln **
** file. I've identified the specific Visual Studio version used to create each header in **
** place of this blank line and indicated each as such [[ VS<VERSION> (PLATFORM TOOLSET) ]]**
*********************************************************************************************
** DO NOT INCLUDE ANYTHING FROM THIS LINE IN YOUR .SLN FILE. REPLACE THIS WITH A NEW LINE **
** CHARACTER (CRLF) OR JUST DELETE IT ENTIRELY. OTHERWISE VISUAL STUDIO WILL NOT BE ABLE **
** TO READ THE .SLN FILE TO OPEN THE SOLUTION. **
*********************************************************************************************
** Additionally, the "VisualStudioVersion" and "MinimumVisualStudioVersion" in the headers **
** for VS2013+ appear to be optional. I can't say if they will remain so in future VS **
** releases, but .sln files without these lines for these VS versions seem to work just **
** fine in my own testing. **
*********************************************************************************************
** Visual Studio 2019 added "Version" to the "# Visual Studio ..." line. **
*********************************************************************************************
--------------- YEAR (PLATFORM TOOLSET VERSION - https://stackoverflow.com/a/33386141) ---------------
--------------- 2002 (v70) ---------------
Microsoft Visual Studio Solution File, Format Version 7.0
--------------- 2003 (v71) ---------------
Microsoft Visual Studio Solution File, Format Version 8.0
--------------- 2005 (Beta 1) ---------------
Microsoft Visual Studio Solution File, Format Version 8.0
# Visual Studio 2005
--------------- 2005 (v80) ---------------
Microsoft Visual Studio Solution File, Format Version 9.0
--------------- 2008 (v90) ---------------
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
--------------- 2010 (v100) ---------------
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
--------------- 2012 (v110) ---------------
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
--------------- 2013 (v120) ---------------
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
--------------- 2015 (v140) ---------------
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
--------------- 2017 (v141) ---------------
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 10.0.40219.1
--------------- 2019 (v142) ---------------
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31321.278
MinimumVisualStudioVersion = 10.0.40219.1
--------------- 2022 (v142) --------------- (TODO: update v142 when stable is released)
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31410.414
MinimumVisualStudioVersion = 10.0.40219.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment