Esempio n. 1
0
        public void MessageRaised(object sender, BuildMessageEventArgs args)
        {
            try
            {
                lock (syncLock)
                {
                    if (args.GetType().Name == "TargetSkippedEventArgs")
                    {
                        if (args is TargetSkippedEventArgs targetSkipped)
                        {
                            TargetSkipped(targetSkipped);
                        }
                        else
                        {
                            targetSkipped = new TargetSkippedEventArgs();
                            targetSkipped.BuildEventContext = args.BuildEventContext;
                            targetSkipped.TargetName        = Reflector.GetTargetNameFromTargetSkipped(args);
                            targetSkipped.TargetFile        = Reflector.GetTargetFileFromTargetSkipped(args);
                            targetSkipped.ParentTarget      = Reflector.GetParentTargetFromTargetSkipped(args);
                            targetSkipped.BuildReason       = Reflector.GetBuildReasonFromTargetSkipped(args);
                            TargetSkipped(targetSkipped);
                        }

                        return;
                    }

                    messageProcessor.Process(args);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Esempio n. 2
0
 private void TargetSkipped(TargetSkippedEventArgs args)
 {
     AddTargetCore(
         args,
         stringTable.Intern(args.TargetName),
         stringTable.Intern(args.ParentTarget),
         stringTable.Intern(args.TargetFile));
 }
Esempio n. 3
0
 private void TargetSkipped(TargetSkippedEventArgs args)
 {
     AddTargetCore(
         args,
         Intern(args.TargetName),
         Intern(args.ParentTarget),
         Intern(args.TargetFile),
         args.BuildReason);
 }
 private void Write(TargetSkippedEventArgs e)
 {
     Write(BinaryLogRecordKind.TargetSkipped);
     WriteMessageFields(e);
     WriteOptionalString(e.TargetFile);
     WriteOptionalString(e.TargetName);
     WriteOptionalString(e.ParentTarget);
     Write((int)e.BuildReason);
 }
 private void Write(TargetSkippedEventArgs e)
 {
     Write(BinaryLogRecordKind.TargetSkipped);
     WriteMessageFields(e, writeMessage: false);
     WriteDeduplicatedString(e.TargetFile);
     WriteDeduplicatedString(e.TargetName);
     WriteDeduplicatedString(e.ParentTarget);
     WriteDeduplicatedString(""); // Condition
     WriteDeduplicatedString(""); // EvaluatedCondition
     Write(true);                 // OriginallySucceeded
     Write((int)e.BuildReason);
 }
Esempio n. 6
0
        private BuildEventArgs ReadTargetSkippedEventArgs()
        {
            var fields = ReadBuildEventArgsFields();

            // Read unused Importance, it defaults to Low
            ReadInt32();
            var targetFile   = ReadOptionalString();
            var targetName   = ReadOptionalString();
            var parentTarget = ReadOptionalString();
            var buildReason  = (TargetBuiltReason)ReadInt32();

            var e = new TargetSkippedEventArgs(
                fields.Message);

            SetCommonFields(e, fields);

            e.ProjectFile  = fields.ProjectFile;
            e.TargetFile   = targetFile;
            e.TargetName   = targetName;
            e.ParentTarget = parentTarget;
            e.BuildReason  = buildReason;

            return(e);
        }
        /// <summary>
        /// Write a provided instance of BuildEventArgs to the BinaryWriter
        /// </summary>
        public void Write(BuildEventArgs e)
        {
            var type = e.GetType().Name;

            // the cases are ordered by most used first for performance
            if (e is BuildMessageEventArgs && type != "ProjectImportedEventArgs" && type != "TargetSkippedEventArgs")
            {
                Write((BuildMessageEventArgs)e);
            }
            else if (e is TaskStartedEventArgs)
            {
                Write((TaskStartedEventArgs)e);
            }
            else if (e is TaskFinishedEventArgs)
            {
                Write((TaskFinishedEventArgs)e);
            }
            else if (e is TargetStartedEventArgs)
            {
                Write((TargetStartedEventArgs)e);
            }
            else if (e is TargetFinishedEventArgs)
            {
                Write((TargetFinishedEventArgs)e);
            }
            else if (e is BuildErrorEventArgs)
            {
                Write((BuildErrorEventArgs)e);
            }
            else if (e is BuildWarningEventArgs)
            {
                Write((BuildWarningEventArgs)e);
            }
            else if (e is ProjectStartedEventArgs)
            {
                Write((ProjectStartedEventArgs)e);
            }
            else if (e is ProjectFinishedEventArgs)
            {
                Write((ProjectFinishedEventArgs)e);
            }
            else if (e is BuildStartedEventArgs)
            {
                Write((BuildStartedEventArgs)e);
            }
            else if (e is BuildFinishedEventArgs)
            {
                Write((BuildFinishedEventArgs)e);
            }
            else if (e is ProjectEvaluationStartedEventArgs)
            {
                Write((ProjectEvaluationStartedEventArgs)e);
            }
            else if (e is ProjectEvaluationFinishedEventArgs)
            {
                Write((ProjectEvaluationFinishedEventArgs)e);
            }
            // The following cases are due to the fact that StructuredLogger.dll
            // only references MSBuild 14.0 .dlls. The following BuildEventArgs types
            // were only introduced in MSBuild 15.3 so we can't refer to them statically.
            // To still provide a good experience to those who are using the BinaryLogger
            // from StructuredLogger.dll against MSBuild 15.3 or later we need to preserve
            // these new events, so use reflection to create our "equivalents" of those
            // and populate them to be binary identical to the originals. Then serialize
            // our copies so that it's impossible to tell what wrote these.
            else if (type == "ProjectEvaluationStartedEventArgs")
            {
                var evaluationStarted = new ProjectEvaluationStartedEventArgs(e.Message);
                evaluationStarted.BuildEventContext = e.BuildEventContext;
                evaluationStarted.ProjectFile       = Reflector.GetProjectFileFromEvaluationStarted(e);
                Write(evaluationStarted);
            }
            else if (type == "ProjectEvaluationFinishedEventArgs")
            {
                var evaluationFinished = new ProjectEvaluationFinishedEventArgs(e.Message);
                evaluationFinished.BuildEventContext = e.BuildEventContext;
                evaluationFinished.ProjectFile       = Reflector.GetProjectFileFromEvaluationFinished(e);
                Write(evaluationFinished);
            }
            else if (type == "ProjectImportedEventArgs")
            {
                var message         = e as BuildMessageEventArgs;
                var projectImported = new ProjectImportedEventArgs(message.LineNumber, message.ColumnNumber, e.Message);
                projectImported.BuildEventContext   = e.BuildEventContext;
                projectImported.ProjectFile         = message.ProjectFile;
                projectImported.ImportedProjectFile = Reflector.GetImportedProjectFile(e);
                projectImported.UnexpandedProject   = Reflector.GetUnexpandedProject(e);
                Write(projectImported);
            }
            else if (type == "TargetSkippedEventArgs")
            {
                var message       = e as BuildMessageEventArgs;
                var targetSkipped = new TargetSkippedEventArgs(e.Message);
                targetSkipped.BuildEventContext = e.BuildEventContext;
                targetSkipped.ProjectFile       = message.ProjectFile;
                targetSkipped.TargetName        = Reflector.GetTargetNameFromTargetSkipped(e);
                targetSkipped.TargetFile        = Reflector.GetTargetFileFromTargetSkipped(e);
                targetSkipped.ParentTarget      = Reflector.GetParentTargetFromTargetSkipped(e);
                targetSkipped.BuildReason       = Reflector.GetBuildReasonFromTargetSkipped(e);
                Write(targetSkipped);
            }
            else
            {
                // convert all unrecognized objects to message
                // and just preserve the message
                var buildMessageEventArgs = new BuildMessageEventArgs(
                    e.Message,
                    e.HelpKeyword,
                    e.SenderName,
                    MessageImportance.Normal,
                    e.Timestamp);
                buildMessageEventArgs.BuildEventContext = e.BuildEventContext ?? BuildEventContext.Invalid;
                Write(buildMessageEventArgs);
            }
        }