in src/Analysis/Codelyzer.Analysis.Build/WorkspaceBuilderHelper.cs [566:609]
private string NormalizePath(string path) =>
path == null ? null : Path.GetFullPath(path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar));
public static string GetFrameworkMsBuildExePath(string programFilesPath = null, string programFilesX86Path = null)
{
// Could not find the tools path, possibly due to https://github.com/Microsoft/msbuild/issues/2369
// Try to poll for it. From https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/4649f55f900a324421bad5a714a2584926a02138/src/StructuredLogViewer/MSBuildLocator.cs
List<string> editions = new List<string> { "Enterprise", "Professional", "Community", "BuildTools" };
var targets = new string[] { "Microsoft.CSharp.targets", "Microsoft.CSharp.CurrentVersion.targets", "Microsoft.Common.targets" };
// "Microsoft.CSharp.CrossTargeting.targets"
var msbuildpath = "";
DirectoryInfo vsDirectory;
var programFiles = programFilesPath ?? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string programFilesX86 = programFilesX86Path ?? System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86);
//2022
vsDirectory = new DirectoryInfo(Path.Combine(programFiles, "Microsoft Visual Studio"));
msbuildpath = GetMsBuildPathFromVSDirectory(vsDirectory, editions, targets);
if (!string.IsNullOrEmpty(msbuildpath))
{
return msbuildpath;
}
// 2019, 2017
vsDirectory = new DirectoryInfo(Path.Combine(programFilesX86, "Microsoft Visual Studio"));
msbuildpath = GetMsBuildPathFromVSDirectory(vsDirectory, editions, targets);
if (!string.IsNullOrEmpty(msbuildpath))
{
return msbuildpath;
}
// 14.0, 12.0
vsDirectory = new DirectoryInfo(Path.Combine(programFilesX86, "MSBuild"));
msbuildpath = GetMsBuildPathFromVSDirectoryBelow15(vsDirectory, editions, targets);
if (!string.IsNullOrEmpty(msbuildpath))
{
return msbuildpath;
}
return msbuildpath;
}