Bug 1275297 - Write VisualStudioVersion to solution file; r?chmanchester
There is probably a way to dynamically retrieve the version. But rather
than take the chance we'd query the wrong thing, let's just parse the
version that Visual Studio writes to the solution file when saving it and
use it.
With this change, generating the VisualStudio build backend should not change
any files unless the build config has changed. This means we can generate
Visual Studio files at will without causing Visual Studio to complain
about the solution and other files changing and needing reloading.
MozReview-Commit-ID: 1udZ72SLEzP
--- a/python/mozbuild/mozbuild/backend/visualstudio.py
+++ b/python/mozbuild/mozbuild/backend/visualstudio.py
@@ -247,25 +247,42 @@ class VisualStudioBackend(CommonBackend)
sources=sources,
debugger=debugger)
projects[basename] = (project_id, basename, item)
return projects
def _write_solution(self, fh, projects):
+ # Visual Studio appears to write out its current version in the
+ # solution file. Instead of trying to figure out what version it will
+ # write, try to parse the version out of the existing file and use it
+ # verbatim.
+ vs_version = None
+ try:
+ with open(fh.name, 'rb') as sfh:
+ for line in sfh:
+ if line.startswith(b'VisualStudioVersion = '):
+ vs_version = line.split(b' = ', 1)[1].strip()
+ except IOError as e:
+ if e.errno != errno.ENOENT:
+ raise
+
format_version, comment_version = visual_studio_product_to_solution_version(self._version)
# This is a Visual C++ Project type.
project_type = '8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942'
# Visual Studio seems to require this header.
fh.write('Microsoft Visual Studio Solution File, Format Version %s\r\n' %
format_version)
fh.write('# Visual Studio %s\r\n' % comment_version)
+ if vs_version:
+ fh.write('VisualStudioVersion = %s\r\n' % vs_version)
+
# Corresponds to VS2013.
fh.write('MinimumVisualStudioVersion = 12.0.31101.0\r\n')
binaries_id = projects['target_binaries'][0]
# Write out entries for each project.
for key in sorted(projects):
project_id, basename, name = projects[key]