Search code examples
visual-studiovisual-studio-2008build-processbuildbuild-automation

Sort Visual Studio build log in "Build Order" style


There is a "Show output from" dropdown list in Visual Studio 2008 "Output" window, which allows viewing build events ordered by thread (Build Order). This is very useful when building big solutions on multi-core machines, as the log entries from those come unsynchronized.

Our organization has the automated build process, where solution(s) are compiled in a batch mode, using something like:

devenv Solution.sln /USEENV /build Release /out buildlog.txt

This will load Solution.sln, buld it in Release configuration and output build log into buildlog.txt.

Problem is: buildlog.txt is an output resembling "Build" output, not "Build Order", and therefore, it is pretty hard to read. Is there a command-line filter or something, which would convert output to "Build Order" format?


Solution

  • Use simple filter, something like that:

    static void Main(string[] args)
    {
        var lines = new Dictionary<int, StringBuilder>();
        var line = Console.In.ReadLine();
        while (line != null)
        {
            int process = 0;
            var re = new Regex(@"^(?<process>\d+)\>.*$");
            if (re.IsMatch(line))
            {
                var match = re.Match(line);
                process = Convert.ToInt32(match.Groups["process"].Value);
            }
    
            if (!lines.ContainsKey(process))
            {
                lines[process] = new StringBuilder();
            }
            lines[process].AppendLine(line);
    
            line = Console.In.ReadLine();
        }
    
        foreach (var i in lines.Keys)
        {
            Console.Write(lines[i]);
        }
    }