示例#1
0
        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(
                                                        loggerFactory: sp.GetService <ILoggerFactory>(),
                                                        assemblyLoader: sp.GetService <IAssemblyLoader>()));

            // Setup the options from configuration
            services.Configure <OmniSharpOptions>(configuration);
            services.AddLogging();

            return(services.BuildServiceProvider());
        }
示例#2
0
        public static IServiceProvider CreateDefaultServiceProvider(
            IOmniSharpEnvironment environment,
            IConfigurationRoot configuration,
            IEventEmitter eventEmitter,
            IServiceCollection services = null,
            Action <ILoggingBuilder> configureLogging = null)
        {
            services ??= new ServiceCollection();

            services.TryAddSingleton(_ => new ManualFileSystemWatcher());
            services.TryAddSingleton <IFileSystemNotifier>(sp => sp.GetRequiredService <ManualFileSystemWatcher>());
            services.TryAddSingleton <IFileSystemWatcher>(sp => sp.GetRequiredService <ManualFileSystemWatcher>());

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

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

            services.AddSingleton <IDotNetCliService, DotNetCliService>();

            // MSBuild
            services.AddSingleton <IMSBuildLocator>(sp =>
                                                    MSBuildLocator.CreateDefault(
                                                        loggerFactory: sp.GetService <ILoggerFactory>(),
                                                        assemblyLoader: sp.GetService <IAssemblyLoader>(),
                                                        msbuildConfiguration: configuration.GetSection("msbuild")));


            // Setup the options from configuration
            services.Configure <OmniSharpOptions>(configuration)
            .PostConfigure <OmniSharpOptions>(OmniSharpOptions.PostConfigure);
            services.AddSingleton(configuration);
            services.AddSingleton <IConfiguration>(configuration);

            services.AddLogging(builder =>
            {
                var workspaceInformationServiceName = typeof(WorkspaceInformationService).FullName;
                var projectEventForwarder           = typeof(ProjectEventForwarder).FullName;

                builder.AddFilter(
                    (category, logLevel) =>
                    environment.LogLevel <= logLevel &&
                    category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) &&
                    !category.Equals(workspaceInformationServiceName, StringComparison.OrdinalIgnoreCase) &&
                    !category.Equals(projectEventForwarder, StringComparison.OrdinalIgnoreCase));

                configureLogging?.Invoke(builder);
            });

            return(services.BuildServiceProvider());
        }
        public AbstractMSBuildTestFixture(ITestOutputHelper output)
            : base(output)
        {
            _assemblyLoader         = new AssemblyLoader(this.LoggerFactory);
            _analyzerAssemblyLoader = ShadowCopyAnalyzerAssemblyLoader.Instance;
            _msbuildLocator         = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, msbuildConfiguration: null);

            // Some tests require MSBuild to be discovered early
            // to ensure that the Microsoft.Build.* assemblies can be located
            _msbuildLocator.RegisterDefaultInstance(this.LoggerFactory.CreateLogger("MSBuildTests"), dotNetInfo: null);
        }
示例#4
0
        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);
        }
示例#5
0
        public AbstractMSBuildTestFixture(ITestOutputHelper output)
            : base(output)
        {
            _assemblyLoader         = new AssemblyLoader(this.LoggerFactory);
            _analyzerAssemblyLoader = ShadowCopyAnalyzerAssemblyLoader.Instance;

            // Since we can only load MSBuild once into our process we need to include
            // prerelease version so that our .NET 7 tests will pass.
            var configuration = new Dictionary <string, string>
            {
                ["sdk:IncludePrereleases"] = bool.TrueString
            }.ToConfiguration();

            _msbuildLocator = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, configuration);

            // Some tests require MSBuild to be discovered early
            // to ensure that the Microsoft.Build.* assemblies can be located
            _msbuildLocator.RegisterDefaultInstance(this.LoggerFactory.CreateLogger("MSBuildTests"), dotNetInfo: null);
        }
示例#6
0
 private static IMSBuildLocator CreateMSBuildLocator(ILoggerFactory loggerFactory,
                                                     IAssemblyLoader assemblyLoader,
                                                     IConfiguration configurationData = null)
 => MSBuildLocator.CreateDefault(loggerFactory, assemblyLoader, configurationData);