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

added msbuild:UseBundledOnly option to force the usage of bundled MSBuild #2038

Merged
merged 5 commits into from
Dec 15, 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
12 changes: 11 additions & 1 deletion src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,23 @@ protected override void DisposeCore(bool disposing)
}

public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration msbuildConfiguration)
=> new MSBuildLocator(loggerFactory, assemblyLoader,
{
var useBundledOnly = msbuildConfiguration.GetValue<bool>("UseBundledOnly");
if (useBundledOnly)
{
var logger = loggerFactory.CreateLogger<MSBuildLocator>();
logger.LogInformation("Because 'UseBundledOnly' is enabled in the configuration, OmniSharp will only use the bundled MSBuild.");
return CreateStandAlone(loggerFactory, assemblyLoader);
}

return new MSBuildLocator(loggerFactory, assemblyLoader,
ImmutableArray.Create<MSBuildInstanceProvider>(
new DevConsoleInstanceProvider(loggerFactory),
new VisualStudioInstanceProvider(loggerFactory),
new MonoInstanceProvider(loggerFactory),
new StandAloneInstanceProvider(loggerFactory),
new UserOverrideInstanceProvider(loggerFactory, msbuildConfiguration)));
}

public static MSBuildLocator CreateStandAlone(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader)
=> new MSBuildLocator(loggerFactory, assemblyLoader,
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.MSBuild/Options/MSBuildOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace OmniSharp.Options
{
public class MSBuildOptions
{
public bool UseBundledOnly { get; set; } = false;
public string ToolsVersion { get; set; }
public string VisualStudioVersion { get; set; }
public string Configuration { get; set; }
Expand Down
18 changes: 18 additions & 0 deletions tests/OmniSharp.MSBuild.Tests/MSBuildSelectionTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OmniSharp.MSBuild.Discovery;
using OmniSharp.Services;
using TestUtility;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -255,6 +259,20 @@ public void StandAloneIsPreferredOverUnsupportedVS(string vsVersion)
msbuildLocator.DeleteFakeInstancesFolders();
}

[Fact]
public void CreateDefault_UseBundledOnly_True_LocatesOnlyStandAloneInstance()
{
var configBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string>()
{
["useBundledOnly"] = "true"
});
var loggerFactory = new LoggerFactory();
var locator = MSBuildLocator.CreateDefault(loggerFactory, new AssemblyLoader(loggerFactory), configBuilder.Build());
var instances = locator.GetInstances();
Assert.Single(instances);
Assert.Equal(DiscoveryType.StandAlone, instances[0].DiscoveryType);
}

private static MSBuildInstance GetStandAloneMSBuildInstance()
{
return new MSBuildInstance(
Expand Down