4
4
5
5
using System ;
6
6
using System . Collections . Generic ;
7
+ using System . Diagnostics ;
7
8
using System . IO ;
8
9
using System . Linq ;
9
10
using System . Runtime . InteropServices ;
@@ -17,6 +18,7 @@ internal static class MonoMSBuildDiscovery
17
18
private static string ? s_monoRuntimeExecutablePath ;
18
19
private static string ? s_monoLibDirPath ;
19
20
private static string ? s_monoMSBuildDirectory ;
21
+ private static string ? s_monoVersionString ;
20
22
21
23
private static IEnumerable < string > GetSearchPaths ( )
22
24
{
@@ -143,7 +145,7 @@ private static IEnumerable<string> GetSearchPaths()
143
145
if ( ! monoMSBuildDir . Exists )
144
146
return null ;
145
147
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
147
149
// https://github.com/OmniSharp/omnisharp-roslyn/blob/dde8119c40f4e3920eb5ea894cbca047033bd9aa/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs#L48-L58
148
150
// ensured we had a correctly normalized path in case the underlying file system might have been case insensitive.
149
151
var versionDirectory =
@@ -159,4 +161,32 @@ private static IEnumerable<string> GetSearchPaths()
159
161
160
162
return s_monoMSBuildDirectory ;
161
163
}
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
+ }
162
192
}
0 commit comments