Exemple #1
0
        public async Task <bool> Run(string projectPath, string logBasePath, string target, string?configuration, List <string>?arguments = null)
        {
            ProcessRunner runner = CreateMSBuildRunner(forBinlog: false);
            string        cfg    = Utilities.FirstOf(configuration, Context.Configuration, Constants.DefaultConfiguration);

            runner.AddQuotedArgument($"/p:Configuration={cfg}");
            runner.AddQuotedArgument($"/bl:{logBasePath}.binlog");
            runner.AddQuotedArgument($"/t:{target}");
            AddArguments(runner, arguments);
            runner.AddQuotedArgument(projectPath);

            string message = GetLogMessage(runner);

            Log.InfoLine(message);

            return(await RunMSBuild(runner));
        }
Exemple #2
0
        public async Task <Dictionary <string, BuildInfo> > GetBuildInfo(string logBasePath)
        {
            var    ret        = new Dictionary <string, BuildInfo> (StringComparer.Ordinal);
            string?binlogPath = GetBinLog(logBasePath);

            if (binlogPath == null)
            {
                return(ret);
            }

            bool echoOutputValue = EchoStandardOutput;

            EchoStandardOutput = false;

            try {
                ProcessRunner runner = CreateMSBuildRunner(forBinlog: true);
                runner.AddArgument("/v:diag");
                runner.AddQuotedArgument(binlogPath);

                using (var outputSink = (OutputSink)SetupOutputSink(runner)) {
                    outputSink.SuppressOutput = true;
                    outputSink.LineCallback   = (string l) => {
                        string line = l.Trim();
                        if (!line.StartsWith(BuildInfoMarker, StringComparison.Ordinal))
                        {
                            return;
                        }

                        BuildInfo?bi = ExtractBuildInfo(line);
                        if (bi == null)
                        {
                            return;
                        }

                        if (ret.ContainsKey(bi.TargetFramework))
                        {
                            throw new InvalidOperationException($"Duplicated target framework '{bi.TargetFramework}' info");
                        }

                        ret.Add(bi.TargetFramework, bi);
                    };

                    if (!await RunMSBuild(runner, setupOutputSink: false))
                    {
                        return(ret);
                    }
                }
            } finally {
                EchoStandardOutput = echoOutputValue;
            }

            return(ret);
        }
Exemple #3
0
        public async Task <bool> Install(string projectPath, string logBasePath, string targetFramework, string?configuration, List <string>?arguments = null)
        {
            ProcessRunner runner = CreateMSBuildRunner(forBinlog: false);
            string        cfg    = Utilities.FirstOf(configuration, Context.Configuration, Constants.DefaultConfiguration);

            runner
            .AddArgument("build")
            .AddArgument("-f")
            .AddQuotedArgument(targetFramework)
            .AddArgument("--no-restore")
            .AddArgument("--configuration")
            .AddQuotedArgument(cfg)
            .AddQuotedArgument($"/bl:{logBasePath}.binlog")
            .AddQuotedArgument("-t:Install");

            AddArguments(runner, arguments);
            runner.AddQuotedArgument(projectPath);

            string message = GetLogMessage(runner);

            Log.InfoLine(message);

            return(await RunMSBuild(runner));
        }
Exemple #4
0
        public async Task <Dictionary <string, string> > GetPropertiesFromBinlog(string logBasePath, HashSet <string> neededProperties)
        {
            var    ret        = new Dictionary <string, string> (StringComparer.Ordinal);
            string?binlogPath = GetBinLog(logBasePath);

            if (binlogPath == null)
            {
                return(ret);
            }

            bool echoOutputValue = EchoStandardOutput;

            EchoStandardOutput = false;
            try {
                ProcessRunner runner = CreateMSBuildRunner(forBinlog: true);
                runner.AddArgument("/v:diag");
                runner.AddQuotedArgument(binlogPath);

                bool propertiesStarted = false;
                int  propertiesFound   = 0;
                using (var outputSink = (OutputSink)SetupOutputSink(runner)) {
                    outputSink.SuppressOutput = true;
                    outputSink.LineCallback   = (string l) => {
                        string line = l.Trim();
                        if (!propertiesStarted)
                        {
                            propertiesStarted = line.EndsWith("Initial Properties:");
                            return;
                        }
                        else if (propertiesFound == neededProperties.Count)
                        {
                            return;
                        }

                        int idx = line.IndexOf('=');
                        if (idx < 0)
                        {
                            return;
                        }

                        string propName = line.Substring(0, idx - 1);
                        if (!neededProperties.Contains(propName))
                        {
                            return;
                        }

                        ret [propName] = line.Substring(idx + 1).Trim();
                        propertiesFound++;
                    };

                    if (!await RunMSBuild(runner, setupOutputSink: false))
                    {
                        return(ret);
                    }
                }
            } finally {
                EchoStandardOutput = echoOutputValue;
            }

            return(ret);
        }