Пример #1
0
        private static async Task InitializePlugin(
            ProjectCacheDescriptor pluginDescriptor,
            CancellationToken cancellationToken,
            Func <PluginLoggerBase> loggerFactory,
            ProjectCachePluginBase plugin
            )
        {
            var logger = loggerFactory();

            try
            {
                await plugin.BeginBuildAsync(
                    new CacheContext(
                        pluginDescriptor.PluginSettings,
                        new DefaultMSBuildFileSystem(),
                        pluginDescriptor.ProjectGraph,
                        pluginDescriptor.EntryPoints),
                    // TODO: Detect verbosity from logging service.
                    logger,
                    cancellationToken);
            }
            catch (Exception e)
            {
                HandlePluginException(e, nameof(ProjectCachePluginBase.BeginBuildAsync));
            }

            if (logger.HasLoggedErrors)
            {
                ProjectCacheException.ThrowForErrorLoggedInsideTheProjectCache("ProjectCacheInitializationFailed");
            }
        }
Пример #2
0
        private async Task BeginBuildAsync(ProjectCacheDescriptor?vsWorkaroundOverrideDescriptor = null)
        {
            var logger = new LoggingServiceToPluginLoggerAdapter(
                _loggingService,
                BuildEventContext.Invalid,
                BuildEventFileInfo.Empty);

            try
            {
                SetState(ProjectCacheServiceState.BeginBuildStarted);

                logger.LogMessage("Initializing project cache plugin", MessageImportance.Low);
                var timer = Stopwatch.StartNew();

                if (_projectCacheDescriptor.VsWorkaround)
                {
                    logger.LogMessage("Running project cache with Visual Studio workaround");
                }

                var projectDescriptor = vsWorkaroundOverrideDescriptor ?? _projectCacheDescriptor;
                await _projectCachePlugin.BeginBuildAsync(
                    new CacheContext(
                        projectDescriptor.PluginSettings,
                        new DefaultMSBuildFileSystem(),
                        projectDescriptor.ProjectGraph,
                        projectDescriptor.EntryPoints),
                    logger,
                    _cancellationToken);

                timer.Stop();
                logger.LogMessage($"Finished initializing project cache plugin in {timer.Elapsed.TotalMilliseconds} ms", MessageImportance.Low);

                SetState(ProjectCacheServiceState.BeginBuildFinished);
            }
            catch (Exception e)
            {
                HandlePluginException(e, nameof(ProjectCachePluginBase.BeginBuildAsync));
            }

            if (logger.HasLoggedErrors)
            {
                ProjectCacheException.ThrowForErrorLoggedInsideTheProjectCache("ProjectCacheInitializationFailed");
            }
        }
Пример #3
0
        // TODO: remove vsWorkaroundOverrideDescriptor after we change VS to set the cache descriptor via build parameters.
        private async Task BeginBuildAsync(ProjectCacheDescriptor?vsWorkaroundOverrideDescriptor = null)
        {
            BuildEventContext  buildEventContext  = BuildEventContext.Invalid;
            BuildEventFileInfo buildEventFileInfo = BuildEventFileInfo.Empty;
            var pluginLogger = new LoggingServiceToPluginLoggerAdapter(
                _loggingService,
                buildEventContext,
                buildEventFileInfo);
            ProjectCacheDescriptor projectDescriptor = vsWorkaroundOverrideDescriptor ?? _projectCacheDescriptor;

            try
            {
                SetState(ProjectCacheServiceState.BeginBuildStarted);
                _loggingService.LogComment(buildEventContext, MessageImportance.Low, "ProjectCacheBeginBuild");
                MSBuildEventSource.Log.ProjectCacheBeginBuildStart(_projectCachePluginTypeName);

                await _projectCachePlugin.BeginBuildAsync(
                    new CacheContext(
                        projectDescriptor.PluginSettings,
                        new DefaultMSBuildFileSystem(),
                        projectDescriptor.ProjectGraph,
                        projectDescriptor.EntryPoints),
                    pluginLogger,
                    _cancellationToken);
            }
            catch (Exception e)
            {
                HandlePluginException(e, nameof(ProjectCachePluginBase.BeginBuildAsync));
            }
            finally
            {
                MSBuildEventSource.Log.ProjectCacheBeginBuildStop(_projectCachePluginTypeName);
                SetState(ProjectCacheServiceState.BeginBuildFinished);
            }

            if (pluginLogger.HasLoggedErrors)
            {
                ProjectCacheException.ThrowForErrorLoggedInsideTheProjectCache("ProjectCacheInitializationFailed");
            }
        }