Skip to content

Commit

Permalink
Use the real MSBuild version during discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Aug 6, 2020
1 parent 96600de commit 2bfebbc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,21 @@ public override ImmutableArray<MSBuildInstance> GetInstances()
var localMSBuildPath = FindLocalMSBuildDirectory();
if (localMSBuildPath != null)
{
microsoftBuildPath = Path.Combine(localMSBuildPath, "Current", "Bin", "Microsoft.Build.dll");

var localRoslynPath = Path.Combine(localMSBuildPath, "Current", "Bin", "Roslyn");
propertyOverrides.Add("CscToolPath", localRoslynPath);
propertyOverrides.Add("CscToolExe", "csc.exe");
}

var msbuildVersionInfo = FileVersionInfo.GetVersionInfo(microsoftBuildPath);
var version = Version.Parse(msbuildVersionInfo.ProductVersion);

return ImmutableArray.Create(
new MSBuildInstance(
nameof(DiscoveryType.Mono),
toolsPath,
new Version(16, 4),
version,
DiscoveryType.Mono,
propertyOverrides.ToImmutable()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using Microsoft.Extensions.Logging;
using OmniSharp.Utilities;
Expand All @@ -25,6 +26,10 @@ public override ImmutableArray<MSBuildInstance> GetInstances()
var toolsPath = Path.Combine(extensionsPath, "Current", "Bin");
var roslynPath = Path.Combine(toolsPath, "Roslyn");

var microsoftBuildPath = Path.Combine(toolsPath, "Microsoft.Build.dll");
var msbuildVersionInfo = FileVersionInfo.GetVersionInfo(microsoftBuildPath);
var version = Version.Parse(msbuildVersionInfo.ProductVersion);

var propertyOverrides = ImmutableDictionary.CreateBuilder<string, string>(StringComparer.OrdinalIgnoreCase);

if (PlatformHelper.IsMono)
Expand All @@ -46,7 +51,7 @@ public override ImmutableArray<MSBuildInstance> GetInstances()
new MSBuildInstance(
nameof(DiscoveryType.StandAlone),
toolsPath,
new Version(16, 4), // we now ship with embedded MsBuild 16.4
version,
DiscoveryType.StandAlone,
propertyOverrides.ToImmutable(),
setMSBuildExePathVariable: true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;

namespace OmniSharp.MSBuild.Discovery.Providers
{
Expand All @@ -22,12 +24,16 @@ public override ImmutableArray<MSBuildInstance> GetInstances()
return ImmutableArray<MSBuildInstance>.Empty;
}

var microsoftBuildPath = Path.Combine(_options.MSBuildPath, "Microsoft.Build.dll");
var msbuildVersionInfo = FileVersionInfo.GetVersionInfo(microsoftBuildPath);
var version = Version.Parse(msbuildVersionInfo.ProductVersion);

var builder = ImmutableArray.CreateBuilder<MSBuildInstance>();
builder.Add(
new MSBuildInstance(
_options.Name ?? $"Overridden MSBuild from {_options.MSBuildPath}",
_options.MSBuildPath,
new Version(99, 0),
version,
DiscoveryType.UserOverride,
_options.PropertyOverrides?.ToImmutableDictionary()));
return builder.ToImmutable();
Expand Down

0 comments on commit 2bfebbc

Please sign in to comment.