diff --git a/src/OmniSharp.Host/CompositionHostBuilder.cs b/src/OmniSharp.Host/CompositionHostBuilder.cs index 28afca728f..76d4972406 100644 --- a/src/OmniSharp.Host/CompositionHostBuilder.cs +++ b/src/OmniSharp.Host/CompositionHostBuilder.cs @@ -59,12 +59,12 @@ public CompositionHost Build(string workingDirectory) // We must register an MSBuild instance before composing MEF to ensure that // our AssemblyResolve event is hooked up first. var msbuildLocator = _serviceProvider.GetRequiredService(); + var dotNetInfo = dotNetCliService.GetInfo(workingDirectory); // Don't register the default instance if an instance is already registered! // This is for tests, where the MSBuild instance may be registered early. if (msbuildLocator.RegisteredInstance == null) { - var dotNetInfo = dotNetCliService.GetInfo(workingDirectory); msbuildLocator.RegisterDefaultInstance(logger, dotNetInfo); } @@ -82,7 +82,8 @@ public CompositionHost Build(string workingDirectory) .WithProvider(MefValueProvider.From(analyzerAssemblyLoader)) .WithProvider(MefValueProvider.From(dotNetCliService)) .WithProvider(MefValueProvider.From(msbuildLocator)) - .WithProvider(MefValueProvider.From(eventEmitter)); + .WithProvider(MefValueProvider.From(eventEmitter)) + .WithProvider(MefValueProvider.From(dotNetInfo)); foreach (var exportDescriptorProvider in _exportDescriptorProviders) { diff --git a/src/OmniSharp.MSBuild/ProjectSystem.cs b/src/OmniSharp.MSBuild/ProjectSystem.cs index cbc2cf9aa9..01f6db98cd 100644 --- a/src/OmniSharp.MSBuild/ProjectSystem.cs +++ b/src/OmniSharp.MSBuild/ProjectSystem.cs @@ -40,6 +40,7 @@ internal class ProjectSystem : IProjectSystem private readonly ILoggerFactory _loggerFactory; private readonly ILogger _logger; private readonly IAnalyzerAssemblyLoader _assemblyLoader; + private readonly DotNetInfo _dotNetInfo; private readonly ImmutableArray _eventSinks; private PackageDependencyChecker _packageDependencyChecker; private ProjectManager _manager; @@ -66,7 +67,8 @@ public ProjectSystem( ILoggerFactory loggerFactory, CachingCodeFixProviderForProjects codeFixesForProjects, IAnalyzerAssemblyLoader assemblyLoader, - [ImportMany] IEnumerable eventSinks) + [ImportMany] IEnumerable eventSinks, + DotNetInfo dotNetInfo) { _environment = environment; _workspace = workspace; @@ -81,6 +83,7 @@ public ProjectSystem( _eventSinks = eventSinks.ToImmutableArray(); _logger = loggerFactory.CreateLogger(); _assemblyLoader = assemblyLoader; + _dotNetInfo = dotNetInfo; } public void Initalize(IConfiguration configuration) @@ -102,8 +105,7 @@ public void Initalize(IConfiguration configuration) _packageDependencyChecker = new PackageDependencyChecker(_loggerFactory, _eventEmitter, _dotNetCli, _options); _loader = new ProjectLoader(_options, _environment.TargetDirectory, _propertyOverrides, _loggerFactory, _sdksPathResolver); - var dotNetInfo = GetDotNetInfo(); - _manager = new ProjectManager(_loggerFactory, _options, _eventEmitter, _fileSystemWatcher, _metadataFileReferenceCache, _packageDependencyChecker, _loader, _workspace, _assemblyLoader, _eventSinks, dotNetInfo); + _manager = new ProjectManager(_loggerFactory, _options, _eventEmitter, _fileSystemWatcher, _metadataFileReferenceCache, _packageDependencyChecker, _loader, _workspace, _assemblyLoader, _eventSinks, _dotNetInfo); Initialized = true; if (_options.LoadProjectsOnDemand) @@ -126,15 +128,6 @@ public void Initalize(IConfiguration configuration) } } - private DotNetInfo GetDotNetInfo() - { - var workingDirectory = string.IsNullOrEmpty(_environment.SolutionFilePath) - ? _environment.TargetDirectory - : Path.GetDirectoryName(_environment.SolutionFilePath); - - return _dotNetCli.GetInfo(workingDirectory); - } - private IEnumerable<(string, ProjectIdInfo)> GetInitialProjectPathsAndIds() { // If a solution was provided, use it. diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index a994f1629b..2a739749e6 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -87,8 +87,9 @@ public static OmniSharpTestHost Create( IEnumerable additionalExports = null, [CallerMemberName] string callerName = "") { + var environment = serviceProvider.GetRequiredService(); var compositionHost = new CompositionHostBuilder(serviceProvider, s_lazyAssemblies.Value, additionalExports) - .Build(workingDirectory: null); + .Build(environment.TargetDirectory); WorkspaceInitializer.Initialize(serviceProvider, compositionHost);