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

Remove MSBuildSDKsPath hack that blocks MSBuild SDK resolvers #1192

Merged
merged 7 commits into from
May 21, 2018
12 changes: 6 additions & 6 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"LegacyDotNetVersion": "1.0.0-preview2-1-003177",
"RequiredMonoVersion": "5.8.0.0",
"DownloadURL": "https://omnisharpdownload.blob.core.windows.net/ext",
"MonoRuntimeMacOS": "mono.osx-5.10.1.20.zip",
"MonoRuntimeLinux32": "mono.linux-x86-5.10.1.20.zip",
"MonoRuntimeLinux64": "mono.linux-x86_64-5.10.1.20.zip",
"MonoFramework": "framework-5.10.1.20.zip",
"MonoMSBuildRuntime": "Microsoft.Build.Runtime.Mono-mono-5.10.1.20.zip",
"MonoMSBuildLib": "Microsoft.Build.Lib.Mono-mono-5.10.1.20.zip",
"MonoRuntimeMacOS": "mono.osx-5.12.0.226.zip",
"MonoRuntimeLinux32": "mono.linux-x86-5.12.0.226.zip",
"MonoRuntimeLinux64": "mono.linux-x86_64-5.12.0.226.zip",
"MonoFramework": "framework-5.12.0.226.zip",
"MonoMSBuildRuntime": "Microsoft.Build.Runtime.Mono-5.12.0.226.zip",
"MonoMSBuildLib": "Microsoft.Build.Lib.Mono-5.12.0.226.zip",
"HostProjects": [
"OmniSharp.Stdio.Driver",
"OmniSharp.Http.Driver"
Expand Down
59 changes: 59 additions & 0 deletions src/OmniSharp.Abstractions/Services/IDotNetCliService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using NuGet.Versioning;
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace OmniSharp.Services
{
public interface IDotNetCliService
{
/// <summary>
/// The path used to launch the .NET CLI. By default, this is "dotnet".
/// </summary>
string DotNetPath { get; }

/// <summary>
/// Launches "dotnet --info" in the given wotking directory and returns a
/// <see cref="DotNetInfo"/> representing the returned information text.
/// </summary>
DotNetInfo GetInfo(string workingDirectory = null);

/// <summary>
/// Launches "dotnet --version" in the given working directory and returns a
/// <see cref="SemanticVersion"/> representing the returned version text.
/// </summary>
SemanticVersion GetVersion(string workingDirectory = null);

/// <summary>
/// Launches "dotnet --version" in the given working directory and determines
/// whether the result represents a "legacy" .NET CLI. If true, this .NET
/// CLI supports project.json development; otherwise, it supports .csproj
/// development.
/// </summary>
bool IsLegacy(string workingDirectory = null);

/// <summary>
/// Determines whether the specified version is from a "legacy"
/// .NET CLI. If true, this .NET CLI supports project.json development;
/// otherwise, it supports .csproj development.
/// </summary>
bool IsLegacy(SemanticVersion version);

/// <summary>
/// Launches "dotnet restore" in the given working directory.
/// </summary>
/// <param name="workingDirectory">The working directory to launch "dotnet restore" within.</param>
/// <param name="arguments">Additional arguments to pass to "dotnet restore"</param>
/// <param name="onFailure">A callback that will be invoked if "dotnet restore" does not
/// return a success code.</param>
Task RestoreAsync(string workingDirectory, string arguments = null, Action onFailure = null);

/// <summary>
/// Launches "dotnet" in the given working directory with the specified arguments.
/// </summary>
/// <param name="arguments"></param>
/// <param name="workingDirectory"></param>
/// <returns></returns>
Process Start(string arguments, string workingDirectory);
}
}
4 changes: 2 additions & 2 deletions src/OmniSharp.DotNet/DotNetProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DotNetProjectSystem : IProjectSystem

private readonly IOmniSharpEnvironment _environment;
private readonly OmniSharpWorkspace _workspace;
private readonly DotNetCliService _dotNetCliService;
private readonly IDotNetCliService _dotNetCliService;
private readonly MetadataFileReferenceCache _metadataFileReferenceCache;
private readonly IEventEmitter _eventEmitter;
private readonly IFileSystemWatcher _fileSystemWatcher;
Expand All @@ -44,7 +44,7 @@ public class DotNetProjectSystem : IProjectSystem
public DotNetProjectSystem(
IOmniSharpEnvironment environment,
OmniSharpWorkspace workspace,
DotNetCliService dotNetCliService,
IDotNetCliService dotNetCliService,
MetadataFileReferenceCache metadataFileReferenceCache,
IEventEmitter eventEmitter,
IFileSystemWatcher fileSystemWatcher,
Expand Down
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/Legacy/LegacyTestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal partial class LegacyTestManager : TestManager
private const string TestExecution_GetTestRunnerProcessStartInfo = "TestExecution.GetTestRunnerProcessStartInfo";
private const string TestExecution_TestResult = "TestExecution.TestResult";

public LegacyTestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public LegacyTestManager(Project project, string workingDirectory, IDotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(project, workingDirectory, dotNetCli, dotNetCliVersion, eventEmitter, loggerFactory.CreateLogger<LegacyTestManager>())
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/OmniSharp.DotNetTest/Services/BaseTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace OmniSharp.DotNetTest.Services
internal abstract class BaseTestService
{
protected readonly OmniSharpWorkspace Workspace;
protected readonly DotNetCliService DotNetCli;
protected readonly IDotNetCliService DotNetCli;
protected readonly IEventEmitter EventEmitter;
protected readonly ILoggerFactory LoggerFactory;

protected BaseTestService(OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
protected BaseTestService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
{
Workspace = workspace;
DotNetCli = dotNetCli;
Expand Down
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/Services/BaseTestService`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OmniSharp.DotNetTest.Services
internal abstract class BaseTestService<TRequest, TResponse> : BaseTestService, IRequestHandler<TRequest, TResponse>
where TRequest: Request
{
protected BaseTestService(OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
protected BaseTestService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(workspace, dotNetCli, eventEmitter, loggerFactory)
{
}
Expand Down
5 changes: 2 additions & 3 deletions src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Composition;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
Expand All @@ -18,7 +17,7 @@ class DebugTestClassService : BaseTestService,
private DebugSessionManager _debugSessionManager;

[ImportingConstructor]
public DebugTestClassService(DebugSessionManager debugSessionManager, OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public DebugTestClassService(DebugSessionManager debugSessionManager, OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(workspace, dotNetCli, eventEmitter, loggerFactory)
{
_debugSessionManager = debugSessionManager;
Expand Down
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/Services/DebugTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class DebugTestService : BaseTestService,
private DebugSessionManager _debugSessionManager;

[ImportingConstructor]
public DebugTestService(DebugSessionManager debugSessionManager, OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public DebugTestService(DebugSessionManager debugSessionManager, OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(workspace, dotNetCli, eventEmitter, loggerFactory)
{
_debugSessionManager = debugSessionManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OmniSharp.DotNetTest.Services
internal class GetTestStartInfoService : BaseTestService<GetTestStartInfoRequest, GetTestStartInfoResponse>
{
[ImportingConstructor]
public GetTestStartInfoService(OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public GetTestStartInfoService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(workspace, dotNetCli, eventEmitter, loggerFactory)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/Services/RunTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OmniSharp.DotNetTest.Services
internal class RunTestService : BaseTestService<RunTestRequest, RunTestResponse>
{
[ImportingConstructor]
public RunTestService(OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public RunTestService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(workspace, dotNetCli, eventEmitter, loggerFactory)
{
}
Expand Down
5 changes: 2 additions & 3 deletions src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Composition;
using System.Composition;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.DotNetTest.Models;
Expand All @@ -13,7 +12,7 @@ namespace OmniSharp.DotNetTest.Services
internal class RunTestsInClassService : BaseTestService<RunTestsInClassRequest, RunTestResponse>
{
[ImportingConstructor]
public RunTestsInClassService(OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public RunTestsInClassService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(workspace, dotNetCli, eventEmitter, loggerFactory)
{
}
Expand Down
8 changes: 4 additions & 4 deletions src/OmniSharp.DotNetTest/TestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OmniSharp.DotNetTest
internal abstract class TestManager : DisposableObject
{
protected readonly Project Project;
protected readonly DotNetCliService DotNetCli;
protected readonly IDotNetCliService DotNetCli;
protected readonly SemanticVersion DotNetCliVersion;
protected readonly IEventEmitter EventEmitter;
protected readonly ILogger Logger;
Expand All @@ -41,7 +41,7 @@ internal abstract class TestManager : DisposableObject

public bool IsConnected => _isConnected;

protected TestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILogger logger)
protected TestManager(Project project, string workingDirectory, IDotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILogger logger)
{
Project = project ?? throw new ArgumentNullException(nameof(project));
WorkingDirectory = workingDirectory ?? throw new ArgumentNullException(nameof(workingDirectory));
Expand All @@ -51,14 +51,14 @@ protected TestManager(Project project, string workingDirectory, DotNetCliService
Logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

public static TestManager Start(Project project, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public static TestManager Start(Project project, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
{
var manager = Create(project, dotNetCli, eventEmitter, loggerFactory);
manager.Connect();
return manager;
}

public static TestManager Create(Project project, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public static TestManager Create(Project project, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
{
var workingDirectory = Path.GetDirectoryName(project.FilePath);

Expand Down
2 changes: 1 addition & 1 deletion src/OmniSharp.DotNetTest/VSTestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OmniSharp.DotNetTest
{
internal class VSTestManager : TestManager
{
public VSTestManager(Project project, string workingDirectory, DotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
public VSTestManager(Project project, string workingDirectory, IDotNetCliService dotNetCli, SemanticVersion dotNetCliVersion, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(project, workingDirectory, dotNetCli, dotNetCliVersion, eventEmitter, loggerFactory.CreateLogger<VSTestManager>())
{
}
Expand Down
26 changes: 12 additions & 14 deletions src/OmniSharp.Host/CompositionHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,19 @@
using OmniSharp.Options;
using OmniSharp.Roslyn;
using OmniSharp.Services;
using OmniSharp.Stdio.Services;

namespace OmniSharp
{
public class CompositionHostBuilder
{
private readonly IServiceProvider _serviceProvider;
private readonly IOmniSharpEnvironment _environment;
private readonly IEventEmitter _eventEmitter;
private readonly IEnumerable<Assembly> _assemblies;

public CompositionHostBuilder(
IServiceProvider serviceProvider,
IOmniSharpEnvironment environment,
IEventEmitter eventEmitter,
IEnumerable<Assembly> assemblies = null)
{
_serviceProvider = serviceProvider;
_environment = environment;
_eventEmitter = eventEmitter;
_assemblies = assemblies ?? Array.Empty<Assembly>();
}

Expand All @@ -45,6 +38,9 @@ public CompositionHost Build()
var memoryCache = _serviceProvider.GetRequiredService<IMemoryCache>();
var loggerFactory = _serviceProvider.GetRequiredService<ILoggerFactory>();
var assemblyLoader = _serviceProvider.GetRequiredService<IAssemblyLoader>();
var environment = _serviceProvider.GetRequiredService<IOmniSharpEnvironment>();
var eventEmitter = _serviceProvider.GetRequiredService<IEventEmitter>();
var dotNetCliService = _serviceProvider.GetRequiredService<IDotNetCliService>();
var config = new ContainerConfiguration();

var fileSystemWatcher = new ManualFileSystemWatcher();
Expand All @@ -64,13 +60,14 @@ public CompositionHost Build()
.WithProvider(MefValueProvider.From<IFileSystemWatcher>(fileSystemWatcher))
.WithProvider(MefValueProvider.From(memoryCache))
.WithProvider(MefValueProvider.From(loggerFactory))
.WithProvider(MefValueProvider.From(_environment))
.WithProvider(MefValueProvider.From(environment))
.WithProvider(MefValueProvider.From(options.CurrentValue))
.WithProvider(MefValueProvider.From(options.CurrentValue.FormattingOptions))
.WithProvider(MefValueProvider.From(assemblyLoader))
.WithProvider(MefValueProvider.From(dotNetCliService))
.WithProvider(MefValueProvider.From(metadataHelper))
.WithProvider(MefValueProvider.From(msbuildLocator))
.WithProvider(MefValueProvider.From(_eventEmitter ?? NullEventEmitter.Instance));
.WithProvider(MefValueProvider.From(eventEmitter));

var parts = _assemblies
.Concat(new[] { typeof(OmniSharpWorkspace).GetTypeInfo().Assembly, typeof(IRequest).GetTypeInfo().Assembly })
Expand Down Expand Up @@ -132,15 +129,20 @@ private static IEnumerable<Type> SafeGetTypes(Assembly a)
}
}

public static IServiceProvider CreateDefaultServiceProvider(IConfiguration configuration, IServiceCollection services = null)
public static IServiceProvider CreateDefaultServiceProvider(IOmniSharpEnvironment environment, IConfiguration configuration, IEventEmitter eventEmitter, IServiceCollection services = null)
{
services = services ?? new ServiceCollection();

services.AddSingleton(environment);
services.AddSingleton(eventEmitter);

// Caching
services.AddSingleton<IMemoryCache, MemoryCache>();
services.AddSingleton<IAssemblyLoader, AssemblyLoader>();
services.AddOptions();

services.AddSingleton<IDotNetCliService, DotNetCliService>();

// MSBuild
services.AddSingleton<IMSBuildLocator>(sp =>
MSBuildLocator.CreateDefault(
Expand All @@ -160,8 +162,6 @@ public CompositionHostBuilder WithOmniSharpAssemblies()

return new CompositionHostBuilder(
_serviceProvider,
_environment,
_eventEmitter,
_assemblies.Concat(assemblies).Distinct()
);
}
Expand All @@ -170,8 +170,6 @@ public CompositionHostBuilder WithAssemblies(params Assembly[] assemblies)
{
return new CompositionHostBuilder(
_serviceProvider,
_environment,
_eventEmitter,
_assemblies.Concat(assemblies).Distinct()
);
}
Expand Down
Loading