From e5a10813edf9f64c8fd7c3e7d1836d474272c46c Mon Sep 17 00:00:00 2001 From: Lluis Sanchez Gual Date: Thu, 26 Mar 2015 10:50:04 +0100 Subject: [PATCH] Fix Mono crash when getting the MSBuild version The implementation of GetVersionInfo() in Mono doesn't set the ProductVersion property, so ProjectCollection.Version crashes when trying to construct the Version object from an empty string. As a workaround, the Version object can be created using the individual components of the product version, which are properly filled by Mono. That's also more efficient that relying on string version parsing. --- src/XMakeBuildEngine/Definition/ProjectCollection.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/XMakeBuildEngine/Definition/ProjectCollection.cs b/src/XMakeBuildEngine/Definition/ProjectCollection.cs index 4698665467d..36cb555e763 100644 --- a/src/XMakeBuildEngine/Definition/ProjectCollection.cs +++ b/src/XMakeBuildEngine/Definition/ProjectCollection.cs @@ -381,7 +381,8 @@ public static Version Version // Use .CodeBase instead of .Location, because .Location doesn't // work when Microsoft.Build.dll has been shadow-copied, for example // in scenarios where NUnit is loading Microsoft.Build. - s_engineVersion = new Version(FileVersionInfo.GetVersionInfo(FileUtilities.ExecutingAssemblyPath).ProductVersion); + var versionInfo = FileVersionInfo.GetVersionInfo(FileUtilities.ExecutingAssemblyPath); + s_engineVersion = new Version (versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart, versionInfo.ProductPrivatePart); } return s_engineVersion;