internal static void OnTargetFinished(MSBuildTarget target)
        {
            target.BuildSessions = GetBuildSessions();

            Runtime.RunInMainThread(() => {
                MSBuildTargetFinished?.Invoke(null, new MSBuildTargetEventArgs(target));
            }).Ignore();
        }
        ProcessWrapper StartProcess(string command, string arguments, string workingDirectory, TextWriter outWriter, TextWriter errorWriter, EventHandler exited)
        {
            int currentSessionId = Interlocked.Increment(ref sessionId);

            var msbuildProcessArguments = new MSBuildProcessArguments(arguments);

            var buildTarget = new MSBuildTarget {
                ProjectName     = GettextCatalog.GetString("Solution"),
                ProjectFileName = GettextCatalog.GetString("Solution"),
                Targets         = msbuildProcessArguments.Targets,
                BuildType       = msbuildProcessArguments.BuildType,
                Dimensions      = GetDimensions(msbuildProcessArguments.Targets)
            };

            buildTarget.Start();

            arguments = MSBuildProcessArguments.AddVerbosity(arguments, Runtime.Preferences.MSBuildVerbosity.Value);
            arguments = MSBuildProcessArguments.AddBinLogFileName(arguments, buildTarget.BinLogFileName);

            lock (buildTargets) {
                buildTargets [currentSessionId] = buildTarget;
            }

            ProjectSystemService.OnTargetStarted(buildTarget);

            var monitor = new MSBuildProcessProgressMonitor(outWriter, errorWriter, buildTarget.LogFileName);

            ProcessWrapper process = Runtime.ProcessService.StartProcess(
                command,
                arguments,
                workingDirectory,
                monitor.Log,
                monitor.ErrorLog,
                exited);

            monitor.Process = process;

            process.Task.ContinueWith(_ => {
                OnMSBuildProcessExited(currentSessionId, monitor);
            });

            return(process);
        }
        void Parse()
        {
            const string targetArgument = "--target:";

            var targetsBuilder = StringBuilderCache.Allocate();

            string[] parts = arguments.Split(' ');
            foreach (string part in parts)
            {
                if (part.StartsWith(targetArgument))
                {
                    AppendTargets(targetsBuilder, part.Substring(targetArgument.Length + 1));
                }
                else if (part.StartsWith("/t") || part.StartsWith("-t"))
                {
                    AppendTargets(targetsBuilder, part.Substring(3));
                }
            }

            Targets   = StringBuilderCache.ReturnAndFree(targetsBuilder);
            BuildType = MSBuildTarget.GetBuildType(Targets);
        }
        public MSBuildTargetMonitor(
            Project project,
            string target,
            ConfigurationSelector configuration,
            TargetEvaluationContext context)
        {
            // Ensure log verbosity is set for non-build targets.
            this.context         = context;
            context.LogVerbosity = Runtime.Preferences.MSBuildVerbosity.Value;

            buildTarget = new MSBuildTarget {
                ProjectName     = project.Name,
                ProjectFileName = project.FileName,
                Targets         = target ?? string.Empty,
                BuildType       = MSBuildTarget.GetBuildType(target),
                Dimensions      = project.GetDimensions(configuration)
            };

            buildTarget.Start();

            ProjectSystemService.OnTargetStarted(buildTarget);
        }
        void OnMSBuildProcessExited(int currentSessionId, MSBuildProcessProgressMonitor monitor)
        {
            MSBuildTarget buildTarget = null;

            using (monitor) {
                lock (buildTargets) {
                    if (buildTargets.TryGetValue(currentSessionId, out buildTarget))
                    {
                        buildTargets.Remove(currentSessionId);
                    }
                    else
                    {
                        return;
                    }
                }

                if (monitor.Process.Task.IsFaulted)
                {
                    buildTarget.OnException(monitor.Process.Task.Exception);
                }
                else if (monitor.Process.Task.IsCanceled)
                {
                    buildTarget.OnResult(MSBuildTargetStatus.Failed);
                }
                else if (monitor.Process.ProcessAsyncOperation.ExitCode == 0)
                {
                    buildTarget.OnResult(MSBuildTargetStatus.Finished);
                }
                else
                {
                    buildTarget.OnResult(MSBuildTargetStatus.Failed);
                }
            }

            ProjectSystemService.OnTargetFinished(buildTarget);
        }
 internal static void OnTargetStarted(MSBuildTarget target)
 {
     Runtime.RunInMainThread(() => {
         MSBuildTargetStarted?.Invoke(null, new MSBuildTargetEventArgs(target));
     }).Ignore();
 }
Пример #7
0
 public MSBuildTargetEventArgs(MSBuildTarget buildTarget)
 {
     BuildTarget = buildTarget;
 }