Esempio n. 1
0
        public BinaryLoggerForwarderProvider(string outputFilePath)
        {
            _source = new BinaryLoggerEventSource();

            _msbuildLogger = new Microsoft.Build.Logging.BinaryLogger()
            {
                Verbosity             = Microsoft.Build.Framework.LoggerVerbosity.Diagnostic,
                CollectProjectImports = Microsoft.Build.Logging.BinaryLogger.ProjectImportsCollectionMode.None,
                Parameters            = $"logfile={outputFilePath}"
            };

            _msbuildLogger.Initialize(_source);
            _source.RaiseBuildStart();

            LogExtensionPoint.AmbientLoggerFactory.AddProvider(this);
        }
Esempio n. 2
0
        public (MSB.Execution.ProjectInstance projectInstance, MSB.Evaluation.Project project, ImmutableArray <MSBuildDiagnostic> diagnostics) BuildProject(
            string filePath, IReadOnlyDictionary <string, string> configurationsInSolution)
        {
            using (_sdksPathResolver.SetSdksPathEnvironmentVariable(filePath))
            {
                var evaluatedProject = EvaluateProjectFileCore(filePath, configurationsInSolution);

                SetTargetFrameworkIfNeeded(evaluatedProject);

                var projectInstance = evaluatedProject.CreateProjectInstance();
                var msbuildLogger   = new MSBuildLogger(_logger);

                var loggers = new List <MSB.Framework.ILogger>()
                {
                    msbuildLogger
                };

                if (_options.GenerateBinaryLogs)
                {
                    var binlogPath   = Path.ChangeExtension(projectInstance.FullPath, ".binlog");
                    var binaryLogger = new MSB.Logging.BinaryLogger()
                    {
                        CollectProjectImports = MSB.Logging.BinaryLogger.ProjectImportsCollectionMode.Embed,
                        Parameters            = binlogPath
                    };

                    loggers.Add(binaryLogger);
                }

                var buildResult = projectInstance.Build(
                    targets: new string[] { TargetNames.Compile, TargetNames.CoreCompile },
                    loggers);

                var diagnostics = msbuildLogger.GetDiagnostics();

                return(buildResult
                    ? (projectInstance, evaluatedProject, diagnostics)
                    : (null, null, diagnostics));
            }
        }