Skip to content
New issue

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

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

Already on GitHub? # to your account

Only run dotnet --info once for the working directory #1925

Merged
merged 3 commits into from
Sep 1, 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
5 changes: 3 additions & 2 deletions src/OmniSharp.Host/CompositionHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMSBuildLocator>();
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);
}

Expand All @@ -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)
{
Expand Down
17 changes: 5 additions & 12 deletions src/OmniSharp.MSBuild/ProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMSBuildEventSink> _eventSinks;
private PackageDependencyChecker _packageDependencyChecker;
private ProjectManager _manager;
Expand All @@ -66,7 +67,8 @@ public ProjectSystem(
ILoggerFactory loggerFactory,
CachingCodeFixProviderForProjects codeFixesForProjects,
IAnalyzerAssemblyLoader assemblyLoader,
[ImportMany] IEnumerable<IMSBuildEventSink> eventSinks)
[ImportMany] IEnumerable<IMSBuildEventSink> eventSinks,
DotNetInfo dotNetInfo)
{
_environment = environment;
_workspace = workspace;
Expand All @@ -81,6 +83,7 @@ public ProjectSystem(
_eventSinks = eventSinks.ToImmutableArray();
_logger = loggerFactory.CreateLogger<ProjectSystem>();
_assemblyLoader = assemblyLoader;
_dotNetInfo = dotNetInfo;
}

public void Initalize(IConfiguration configuration)
Expand All @@ -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)
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion tests/TestUtility/OmniSharpTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ public static OmniSharpTestHost Create(
IEnumerable<ExportDescriptorProvider> additionalExports = null,
[CallerMemberName] string callerName = "")
{
var environment = serviceProvider.GetRequiredService<IOmniSharpEnvironment>();
var compositionHost = new CompositionHostBuilder(serviceProvider, s_lazyAssemblies.Value, additionalExports)
.Build(workingDirectory: null);
.Build(environment.TargetDirectory);

WorkspaceInitializer.Initialize(serviceProvider, compositionHost);

Expand Down