public static OmniSharpTestHost Create( string path = null, ITestOutputHelper testOutput = null, IEnumerable <KeyValuePair <string, string> > configurationData = null, DotNetCliVersion dotNetCliVersion = DotNetCliVersion.Current, IEnumerable <ExportDescriptorProvider> additionalExports = null) { var environment = new OmniSharpEnvironment(path, logLevel: LogLevel.Trace); var loggerFactory = new LoggerFactory().AddXunit(testOutput); var logger = loggerFactory.CreateLogger <OmniSharpTestHost>(); var sharedTextWriter = new TestSharedTextWriter(testOutput); var dotNetCliService = CreateTestDotNetCliService(dotNetCliVersion, loggerFactory); var info = dotNetCliService.GetInfo(); logger.LogInformation($"Using .NET CLI: {info.Version}"); var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); builder.AddInMemoryCollection(configurationData); // We need to set the "UseLegacySdkResolver" for tests because // MSBuild's SDK resolver will not be able to locate the .NET Core SDKs // that we install locally in the ".dotnet" and ".dotnet-legacy" directories. // This property will cause the MSBuild project loader to set the // MSBuildSDKsPath environment variable to the correct path "Sdks" folder // within the appropriate .NET Core SDK. var msbuildProperties = new Dictionary <string, string>() { [$"MSBuild:{nameof(MSBuildOptions.UseLegacySdkResolver)}"] = "true", [$"MSBuild:{nameof(MSBuildOptions.MSBuildSDKsPath)}"] = Path.Combine(info.BasePath, "Sdks") }; builder.AddInMemoryCollection(msbuildProperties); var configuration = builder.Build(); var serviceProvider = new TestServiceProvider(environment, loggerFactory, sharedTextWriter, configuration, NullEventEmitter.Instance, dotNetCliService); var compositionHost = new CompositionHostBuilder(serviceProvider, s_lazyAssemblies.Value, additionalExports) .Build(); var workspace = compositionHost.GetExport <OmniSharpWorkspace>(); WorkspaceInitializer.Initialize(serviceProvider, compositionHost, configuration, logger); var host = new OmniSharpTestHost(serviceProvider, loggerFactory, workspace, compositionHost); // Force workspace to be updated var service = host.GetWorkspaceInformationService(); service.Handle(new WorkspaceInformationRequest()).Wait(); return(host); }
public static OmniSharpTestHost Create(string path = null, ITestOutputHelper testOutput = null, IEnumerable <KeyValuePair <string, string> > configurationData = null, DotNetCliVersion dotNetCliVersion = DotNetCliVersion.Current) { var dotNetPath = Path.Combine( TestAssets.Instance.RootFolder, GetDotNetCliFolderName(dotNetCliVersion), "dotnet"); if (!File.Exists(dotNetPath)) { dotNetPath = Path.ChangeExtension(dotNetPath, ".exe"); } if (!File.Exists(dotNetPath)) { throw new InvalidOperationException($"Local .NET CLI path does not exist. Did you run build.(ps1|sh) from the command line?"); } var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder(); builder.AddInMemoryCollection(configurationData); var configuration = builder.Build(); var environment = new OmniSharpEnvironment(path, logLevel: LogLevel.Trace); var loggerFactory = new LoggerFactory().AddXunit(testOutput); var sharedTextWriter = new TestSharedTextWriter(testOutput); var serviceProvider = new TestServiceProvider(environment, loggerFactory, sharedTextWriter, configuration); var compositionHost = new CompositionHostBuilder(serviceProvider, environment, NullEventEmitter.Instance) .WithAssemblies(s_lazyAssemblies.Value) .Build(); var workspace = compositionHost.GetExport <OmniSharpWorkspace>(); var logger = loggerFactory.CreateLogger <OmniSharpTestHost>(); var dotNetCli = compositionHost.GetExport <DotNetCliService>(); dotNetCli.SetDotNetPath(dotNetPath); var version = dotNetCli.GetVersion(); logger.LogInformation($"Using .NET CLI: {version}"); var oldMSBuildSdksPath = SetMSBuildSdksPath(dotNetCli); WorkspaceInitializer.Initialize(serviceProvider, compositionHost, configuration, logger); var host = new OmniSharpTestHost(serviceProvider, loggerFactory, workspace, compositionHost, oldMSBuildSdksPath); // Force workspace to be updated var service = host.GetWorkspaceInformationService(); service.Handle(new WorkspaceInformationRequest()).Wait(); return(host); }
public static OmniSharpTestHost Create(string path = null, ITestOutputHelper testOutput = null, IEnumerable <KeyValuePair <string, string> > configurationData = null, bool useLegacyDotNetCli = false) { var dotNetPath = Path.Combine( TestAssets.Instance.RootFolder, useLegacyDotNetCli ? ".dotnet-legacy" : ".dotnet", "dotnet"); if (!File.Exists(dotNetPath)) { dotNetPath = Path.ChangeExtension(dotNetPath, ".exe"); } if (!File.Exists(dotNetPath)) { throw new InvalidOperationException($"Local .NET CLI path does not exist. Did you run build.(ps1|sh) from the command line?"); } var builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(configurationData); var configuration = builder.Build(); var environment = new OmniSharpEnvironment(path); var loggerFactory = new LoggerFactory().AddXunit(testOutput); var sharedTextWriter = new TestSharedTextWriter(testOutput); var serviceProvider = new TestServiceProvider(environment, loggerFactory, sharedTextWriter); var omnisharpOptions = new OmniSharpOptions(); ConfigurationBinder.Bind(configuration, omnisharpOptions); var compositionHost = Startup.CreateCompositionHost( serviceProvider, options: omnisharpOptions, assemblies: s_lazyAssemblies.Value); var workspace = compositionHost.GetExport <OmniSharpWorkspace>(); var logger = loggerFactory.CreateLogger <OmniSharpTestHost>(); var dotNetCli = compositionHost.GetExport <DotNetCliService>(); dotNetCli.SetDotNetPath(dotNetPath); var workspaceHelper = new WorkspaceHelper(compositionHost, configuration, omnisharpOptions, loggerFactory); workspaceHelper.Initialize(workspace); return(new OmniSharpTestHost(serviceProvider, loggerFactory, workspace, compositionHost)); }