Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the real MSBuild version during discovery #1876

Merged
merged 3 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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";
}

Expand Down
13 changes: 13 additions & 0 deletions src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@ 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 version = GetMSBuildVersion(microsoftBuildPath);

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,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
Expand All @@ -25,6 +27,8 @@ public override ImmutableArray<MSBuildInstance> 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<string, string>(StringComparer.OrdinalIgnoreCase);

if (PlatformHelper.IsMono)
Expand All @@ -46,7 +50,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,14 @@ public override ImmutableArray<MSBuildInstance> GetInstances()
return ImmutableArray<MSBuildInstance>.Empty;
}

var version = GetMSBuildVersion(Path.Combine(_options.MSBuildPath, "Microsoft.Build.dll"));

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
11 changes: 11 additions & 0 deletions tools/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.37.0" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.1" />
<package id="Microsoft.Build" version="16.8.0-preview-20371-01" />
<package id="Microsoft.Build.Framework" version="16.8.0-preview-20371-01" />
<package id="Microsoft.Build.Runtime" version="16.8.0-preview-20371-01" />
Expand Down Expand Up @@ -29,5 +30,15 @@
<package id="SQLitePCLRaw.bundle_green" version="1.1.2" />
<package id="SQLitePCLRaw.core" version="1.1.2" />
<package id="SQLitePCLRaw.provider.e_sqlite3.net45" version="1.1.2" />
<package id="System.Buffers" version="4.5.1" />
<package id="System.Collections.Immutable" version="1.7.1" />
<package id="System.Memory" version="4.5.4" />
<package id="System.Numerics.Vectors" version="4.5.0" />
<package id="System.Resources.Extensions" version="4.7.1" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" />
<package id="System.Text.Encodings.Web" version="4.7.1" />
<package id="System.Text.Json" version="4.7.1" />
<package id="System.Threading.Tasks.Dataflow" version="4.11.1" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" />
<package id="xunit.runner.console" version="2.4.0" />
</packages>