Skip to content

Commit 91bdff8

Browse files
committed
Return MSBuildLocation for Mono
1 parent 584999e commit 91bdff8

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Workspaces/MSBuild/BuildHost/BuildHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public BuildHost(BuildHostLogger logger, ImmutableDictionary<string, string> glo
8686
if (monoMSBuildDirectory != null)
8787
{
8888
MSBuildLocator.RegisterMSBuildPath(monoMSBuildDirectory);
89+
_msBuildLocation = new(monoMSBuildDirectory, MonoMSBuildDiscovery.GetMonoMSBuildVersion());
8990
_logger.LogInformation($"Registered MSBuild instance at {monoMSBuildDirectory}");
9091
}
9192
else

src/Workspaces/MSBuild/BuildHost/Rpc/Contracts/MonoMSBuildDiscovery.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
78
using System.IO;
89
using System.Linq;
910
using System.Runtime.InteropServices;
@@ -17,6 +18,7 @@ internal static class MonoMSBuildDiscovery
1718
private static string? s_monoRuntimeExecutablePath;
1819
private static string? s_monoLibDirPath;
1920
private static string? s_monoMSBuildDirectory;
21+
private static string? s_monoVersionString;
2022

2123
private static IEnumerable<string> GetSearchPaths()
2224
{
@@ -143,7 +145,7 @@ private static IEnumerable<string> GetSearchPaths()
143145
if (!monoMSBuildDir.Exists)
144146
return null;
145147

146-
// Inside this is either a Current directory or a 15.0 directory, so find it; the previous code at
148+
// Inside this is either a Current directory or a 15.0 directory, so find it; the previous code at
147149
// https://github.com/OmniSharp/omnisharp-roslyn/blob/dde8119c40f4e3920eb5ea894cbca047033bd9aa/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs#L48-L58
148150
// ensured we had a correctly normalized path in case the underlying file system might have been case insensitive.
149151
var versionDirectory =
@@ -159,4 +161,32 @@ private static IEnumerable<string> GetSearchPaths()
159161

160162
return s_monoMSBuildDirectory;
161163
}
164+
165+
public static string? GetMonoMSBuildVersion()
166+
{
167+
Contract.ThrowIfTrue(PlatformInformation.IsWindows);
168+
169+
if (s_monoVersionString == null)
170+
{
171+
var monoMSBuildDirectory = GetMonoMSBuildDirectory();
172+
if (monoMSBuildDirectory == null)
173+
{
174+
return null;
175+
}
176+
177+
// Look for Microsoft.Build.dll in the tools path. If it isn't there, this is likely a Mono layout on Linux
178+
// where the 'msbuild' package has not been installed.
179+
var monoMSBuildPath = Path.Combine(monoMSBuildDirectory, "Microsoft.Build.dll");
180+
try
181+
{
182+
var msbuildVersionInfo = FileVersionInfo.GetVersionInfo(monoMSBuildPath);
183+
s_monoVersionString = msbuildVersionInfo.ProductVersion;
184+
}
185+
catch (FileNotFoundException)
186+
{
187+
}
188+
}
189+
190+
return s_monoVersionString;
191+
}
162192
}

0 commit comments

Comments
 (0)