Skip to content

Commit d9ff8cd

Browse files
Merge pull request #7 from jamesashley1/hTK-IconGenUpdate
fix bug in finding msbuild.exe path for vs 2017
2 parents 496d101 + b59c80d commit d9ff8cd

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

Assets/HoloToolkit/BuildAndDeploy/Editor/BuildDeployTools.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,39 +88,48 @@ public static string CalcMSBuildPath(string msBuildVersion)
8888
}
8989

9090
// For MSBuild 15+ we should to use vswhere to give us the correct instance
91-
string output = @"/C cd ""%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"" && vswhere -version " + msBuildVersion + " -products * -requires Microsoft.Component.MSBuild -property installationPath";
91+
string output = @"/C vswhere -version " + msBuildVersion + " -products * -requires Microsoft.Component.MSBuild -property installationPath";
92+
93+
// get the right program files path based on whether the pc is x86 or x64
94+
string programFiles = @"C:\Program Files\";
95+
if (System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", EnvironmentVariableTarget.Machine).ToString() == "AMD64")
96+
{
97+
programFiles = @"C:\Program Files (x86)\";
98+
}
99+
92100

93101
var vswherePInfo = new System.Diagnostics.ProcessStartInfo
94102
{
95103
FileName = "cmd.exe",
96104
CreateNoWindow = true,
97105
UseShellExecute = false,
98106
RedirectStandardOutput = true,
99-
Arguments = output
107+
RedirectStandardError = false,
108+
Arguments = output,
109+
WorkingDirectory = programFiles + @"Microsoft Visual Studio\Installer"
100110
};
101111

112+
102113
using (var vswhereP = new System.Diagnostics.Process())
103114
{
104115
vswhereP.StartInfo = vswherePInfo;
105116
vswhereP.Start();
106117
output = vswhereP.StandardOutput.ReadToEnd();
107118
vswhereP.WaitForExit();
108-
vswhereP.Close();
109-
vswhereP.Dispose();
110119
}
111120

112-
string externalScriptingEditorPath = EditorPrefs.GetString("kScriptsDefaultApp");
113121
string[] paths = output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
114122

115-
for (int i = 0; i < paths.Length; i++)
123+
124+
// if there are multiple 2017 installs,
125+
// prefer enterprise, then pro, then community
126+
string bestPath = paths.OrderBy(p => p.ToLower().Contains("enterprise")).ThenBy(p => p.ToLower().Contains("professional")).First();
127+
if (File.Exists(bestPath + @"\MSBuild\" + msBuildVersion + @"\Bin\MSBuild.exe"))
116128
{
117-
paths[i] = paths[i].Replace(Environment.NewLine, "");
118-
if (externalScriptingEditorPath.Contains(paths[i]))
119-
{
120-
return paths[i] + @"\MSBuild\" + msBuildVersion + @"\Bin\MSBuild.exe";
121-
}
129+
return bestPath + @"\MSBuild\" + msBuildVersion + @"\Bin\MSBuild.exe";
122130
}
123131

132+
124133
Debug.LogError("Unable to find a valid path to Visual Studio Instance!");
125134
return string.Empty;
126135
}

0 commit comments

Comments
 (0)