public void Run(string binLogFilePath, string outputFilePath) { var build = BinaryLog.ReadBuild(binLogFilePath); var strings = build.StringTable.Instances.OrderBy(s => s).ToArray(); Serialization.WriteStringsToFile(outputFilePath, strings); }
//[Fact] public void LoadBinlog() { var sw = Stopwatch.StartNew(); var build = BinaryLog.ReadBuild(@"C:\temp\vsmac.binlog"); var elapsed = sw.Elapsed; output.WriteLine(elapsed.ToString()); }
private static void PrintTargets(string binLogFilePath) { var build = BinaryLog.ReadBuild(binLogFilePath); build.VisitAllChildren <Project>(p => { p.VisitAllChildren <Target>(t => Console.WriteLine(t.Name)); }); }
public BuildLog(string filePath) { var successSet = false; var root = BinaryLog.ReadBuild(filePath); root.VisitAllChildren <Build>(processBuild); root.VisitAllChildren <Target>(processTarget); root.VisitAllChildren <Task>(x => tasks.Add(x.Name)); root.VisitAllChildren <Message>(x => Messages.Add(x.Text)); root.VisitAllChildren <Warning>(x => Warnings.Add(x.Text)); root.VisitAllChildren <Error>(x => Errors.Add(x.Text)); root.VisitAllChildren <Property>(x => properties[x.Name] = x.Value); root.VisitAllChildren <NamedNode>(processNamedNode); void processBuild(Build build) { Debug.Assert(!successSet, "Build should be processed only once"); BuildSucceeded = build.Succeeded; successSet = true; } void processTarget(Target target) { if (target.Id >= 0) // If our target fails with error, we still want to register it. Skipped have log Id = -1 { Targets.Add(target.Name); } } void processNamedNode(NamedNode node) { if (node is AddItem addItem) { if (!items.ContainsKey(addItem.Name)) { items.Add(addItem.Name, new List <BuildItem>()); } items[addItem.Name].AddRange(addItem.Children.OfType <Item>().Select(x => new BuildItem(x))); } else if (node is RemoveItem removeItem && items.TryGetValue(removeItem.Name, out var list)) { foreach (var item in removeItem.Children.OfType <Item>()) { var index = FindIndex(item); while (index >= 0) { list.RemoveAt(index); index = FindIndex(item); } } int FindIndex(Item item) => list.FindIndex(x => x.Text.Equals(item.Text, StringComparison.OrdinalIgnoreCase)); } } }
public string GetPropertyValue(string name) { if (executionResult == null) { throw new InvalidOperationException($"Must build something first"); } var build = BinaryLog.ReadBuild(executionResult.BinLogPath); var props = build.FindChildrenRecursive <Property> (v => v.Name == name); return(props.LastOrDefault()?.Value ?? string.Empty); }
public MSBuildItem [] GetItems(ProjectPaths project, string name) { if (executionResult == null) { throw new InvalidOperationException($"Must build something first"); } var build = BinaryLog.ReadBuild(executionResult.BinLogPath); var rv = new List <MSBuildItem> (); // Items inside ItemGroups var items = build.FindChildrenRecursive <Item> (v => (v.Parent as Folder)?.Name == name); foreach (var item in items) { rv.Add(CreateItem(item)); } // Items as output from tasks var resolvedProjectPath = PathUtils.ResolveSymbolicLinks(project.ProjectCSProjPath); var outputItems = build.FindChildrenRecursive <Item> (v => { var parent = v.Parent as NamedNode; if (parent?.Name != name || !(parent is Parameter)) { return(false); } parent = parent.Parent as NamedNode; if (parent?.Name != "OutputItems" || !(parent is Folder)) { return(false); } // There can be output from multiple projects, make sure we filter to the // project we're interested in. var target = parent.GetNearestParent <Target> (); var projectPath = PathUtils.ResolveSymbolicLinks(target.Project.ProjectFile); return(projectPath == resolvedProjectPath); }); foreach (var item in outputItems) { rv.Add(CreateItem(item)); } return(rv.ToArray()); }
double GetDurationFromBinLog(ProjectBuilder builder) { var binlog = Path.Combine(Root, builder.ProjectDirectory, "msbuild.binlog"); FileAssert.Exists(binlog); try { var build = BinaryLog.ReadBuild(binlog); var duration = build .FindChildrenRecursive <Project> () .Aggregate(TimeSpan.Zero, (duration, project) => duration + project.Duration); if (duration == TimeSpan.Zero) { throw new InvalidDataException($"No project build duration found in {binlog}"); } return(duration.TotalMilliseconds); } catch (NotSupportedException) { // See: https://github.com/dotnet/msbuild/issues/6225 Assert.Ignore($"Test requires an updated MSBuild.StructuredLogger"); return(0); } }