diff --git a/build.cake b/build.cake index 9a4c96e14a..b8a040804b 100644 --- a/build.cake +++ b/build.cake @@ -210,7 +210,22 @@ Task("CreateMSBuildFolder") "Microsoft.Build.Tasks.v4.0", "Microsoft.Build.Tasks.v12.0", "Microsoft.Build.Utilities.v4.0", - "Microsoft.Build.Utilities.v12.0" + "Microsoft.Build.Utilities.v12.0", + }; + + var msBuildDependencies = new [] + { + "Microsoft.Bcl.AsyncInterfaces", + "System.Buffers", + "System.Collections.Immutable", + "System.Memory", + "System.Numerics.Vectors", + "System.Resources.Extensions", + "System.Runtime.CompilerServices.Unsafe", + "System.Text.Encodings.Web", + "System.Text.Json", + "System.Threading.Tasks.Dataflow", + "System.Threading.Tasks.Extensions", }; var msbuildRuntimeFiles = new [] @@ -244,15 +259,8 @@ Task("CreateMSBuildFolder") "Microsoft.Xaml.targets", "MSBuild.dll", "MSBuild.dll.config", - "System.Buffers.dll", - "System.Collections.Immutable.dll", - "System.Memory.dll", - "System.Numerics.Vectors.dll", - "System.Reflection.Metadata.dll", - "System.Resources.Extensions.dll", - "System.Threading.Tasks.Dataflow.dll", "Workflow.VisualBasic.targets", - "Workflow.targets" + "Workflow.targets", }; string sdkResolverTFM; @@ -280,6 +288,19 @@ Task("CreateMSBuildFolder") } } + Information("Copying MSBuild dependencies..."); + + foreach (var dependency in msBuildDependencies) + { + var dependencyFileName = dependency + ".dll"; + var dependencySourcePath = CombinePaths(env.Folders.Tools, dependency, "lib", "netstandard2.0", dependencyFileName); + var dependencyTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, dependencyFileName); + if (FileHelper.Exists(dependencySourcePath)) + { + FileHelper.Copy(dependencySourcePath, dependencyTargetPath); + } + } + sdkResolverTFM = "net472"; } else @@ -312,7 +333,7 @@ Task("CreateMSBuildFolder") { var libraryFileName = library + ".dll"; - // copy MSBuild from current Mono (should be 6.4.0+) + // copy MSBuild from current Mono var librarySourcePath = CombinePaths(monoMSBuildPath, libraryFileName); var libraryTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, libraryFileName); if (FileHelper.Exists(librarySourcePath)) @@ -321,6 +342,21 @@ Task("CreateMSBuildFolder") } } + Information("Copying MSBuild depednencies..."); + + foreach (var dependency in msBuildDependencies) + { + var dependencyFileName = dependency + ".dll"; + + // copy MSBuild from current Mono + var dependencySourcePath = CombinePaths(monoMSBuildPath, dependencyFileName); + var dependencyTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, dependencyFileName); + if (FileHelper.Exists(dependencySourcePath)) + { + FileHelper.Copy(dependencySourcePath, dependencyTargetPath); + } + } + sdkResolverTFM = "netstandard2.0"; } diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs index 1e93157d77..f5f4d58f4b 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Immutable; +using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.Extensions.Logging; +using NuGet.Versioning; namespace OmniSharp.MSBuild.Discovery { @@ -96,5 +98,16 @@ private static string FindLocalMSBuildFromSolution() ? result : null; } + + protected static Version GetMSBuildVersion(string microsoftBuildPath) + { + var msbuildVersionInfo = FileVersionInfo.GetVersionInfo(microsoftBuildPath); + var semanticVersion = SemanticVersion.Parse(msbuildVersionInfo.ProductVersion); + return new Version( + semanticVersion.Major, + semanticVersion.Minor, + semanticVersion.Patch + ); + } } } diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/MonoInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/MonoInstanceProvider.cs index f019ad4f55..4736c2b3ce 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/MonoInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/MonoInstanceProvider.cs @@ -103,16 +103,20 @@ public override ImmutableArray 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 version = GetMSBuildVersion(microsoftBuildPath); + return ImmutableArray.Create( new MSBuildInstance( nameof(DiscoveryType.Mono), toolsPath, - new Version(16, 4), + version, DiscoveryType.Mono, propertyOverrides.ToImmutable())); } diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/StandAloneInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/StandAloneInstanceProvider.cs index b70b44b792..30276dcb44 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/StandAloneInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/StandAloneInstanceProvider.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Immutable; +using System.Diagnostics; using System.IO; using Microsoft.Extensions.Logging; +using NuGet.Versioning; using OmniSharp.Utilities; namespace OmniSharp.MSBuild.Discovery.Providers @@ -25,6 +27,8 @@ public override ImmutableArray GetInstances() var toolsPath = Path.Combine(extensionsPath, "Current", "Bin"); var roslynPath = Path.Combine(toolsPath, "Roslyn"); + var version = GetMSBuildVersion(Path.Combine(toolsPath, "Microsoft.Build.dll")); + var propertyOverrides = ImmutableDictionary.CreateBuilder(StringComparer.OrdinalIgnoreCase); if (PlatformHelper.IsMono) @@ -46,7 +50,7 @@ public override ImmutableArray 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)); diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs index 30374e9a1a..a10a6194ba 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs @@ -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 { @@ -22,12 +24,14 @@ public override ImmutableArray GetInstances() return ImmutableArray.Empty; } + var version = GetMSBuildVersion(Path.Combine(_options.MSBuildPath, "Microsoft.Build.dll")); + var builder = ImmutableArray.CreateBuilder(); 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(); diff --git a/tools/packages.config b/tools/packages.config index c108b1a872..0f487fa89f 100644 --- a/tools/packages.config +++ b/tools/packages.config @@ -1,6 +1,7 @@ + @@ -29,5 +30,15 @@ + + + + + + + + + +