-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectBuildInfo.cs
More file actions
124 lines (100 loc) · 5.25 KB
/
ProjectBuildInfo.cs
File metadata and controls
124 lines (100 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Build.Framework;
namespace ParallelBuildDebuggingLogger
{
class ProjectBuildInfo
{
public ProjectStartedEventArgs StartedEventArgs { get; private set; }
public int ProjectInstanceId { get; set; }
public int ParentProjectInstanceId { get; set; }
public IDictionary<string, string> GlobalProperties { get; set; }
private Dictionary<string, SortedSet<GlobalPropertyValue>> _globalPropertySubsets;
private HashSet<string> _distinctSolutionConfigurations;
public IEnumerable<GlobalPropertyValue> UniqueProperties
{
get
{
var properties = new SortedSet<GlobalPropertyValue>(GlobalProperties.Select(GlobalPropertyValue.FromKeyValuePair));
var commonSubset = _globalPropertySubsets[StartedEventArgs.ProjectFile];
properties.ExceptWith(commonSubset);
// If there are multiple distinct SolutionConfiguration values, include SolutionConfiguration in unique properties
if (_distinctSolutionConfigurations.Count > 1 && GlobalProperties.ContainsKey("SolutionConfiguration"))
{
var solutionConfigProperty = new GlobalPropertyValue
{
Name = "SolutionConfiguration",
Value = GlobalProperties["SolutionConfiguration"]
};
properties.Add(solutionConfigProperty);
}
return properties;
}
}
public Dictionary<string, string> RemovedProperties { get; set; } = new Dictionary<string, string>();
public ProjectBuildInfo(ProjectStartedEventArgs projectStartedEventArgs, IReadOnlyDictionary<int, ProjectBuildInfo> otherProjects, Dictionary<string, SortedSet<GlobalPropertyValue>> globalPropertySubsets, HashSet<string> distinctSolutionConfigurations)
{
StartedEventArgs = projectStartedEventArgs;
ParentProjectInstanceId = projectStartedEventArgs.ParentProjectBuildEventContext.ProjectInstanceId;
ProjectInstanceId = projectStartedEventArgs.BuildEventContext.ProjectInstanceId;
GlobalProperties = projectStartedEventArgs.GlobalProperties ?? new Dictionary<string, string>();
_globalPropertySubsets = globalPropertySubsets;
_distinctSolutionConfigurations = distinctSolutionConfigurations;
if (GlobalProperties == null)
{
return;
}
if (otherProjects.TryGetValue(ParentProjectInstanceId, out ProjectBuildInfo other))
{
foreach (var propertyName in other.GlobalProperties.Keys)
{
if (!GlobalProperties.TryGetValue(propertyName, out _))
{
RemovedProperties[propertyName] = other.GlobalProperties[propertyName];
}
}
}
}
public override string ToString()
{
string upDescription = string.Empty;
string rpDescription = string.Empty;
if (UniqueProperties.Any())
{
upDescription = $" + <{string.Join("; ", UniqueProperties.Select(up => $"{up.Name} = {((up.Name == "CurrentSolutionConfigurationContents" || up.Name == "RestoreGraphProjectInput" || (up.Name == "SolutionConfiguration" && _distinctSolutionConfigurations.Count <= 1)) ? "{elided}" : up.Value)}"))}>";
}
if (RemovedProperties.Any())
{
rpDescription = $" - <{string.Join("; ", RemovedProperties.Select(rp => rp.Key))}>";
}
return
$"{{{ProjectInstanceId}: \"{StartedEventArgs.ProjectFile}\"{upDescription}{rpDescription}}}";
}
public string ToHtml()
{
string upDescription = string.Empty;
string rpDescription = string.Empty;
if (UniqueProperties.Any())
{
upDescription = $"<div class=\"uniqueproperties\"><table><tr><td>{string.Join("</td></tr><tr><td>", UniqueProperties.Select(up => $"{up.Name}</td><td>{((up.Name == "CurrentSolutionConfigurationContents" || up.Name == "RestoreGraphProjectInput" || (up.Name == "SolutionConfiguration" && _distinctSolutionConfigurations.Count <= 1)) ? "{elided}" : up.Value)}"))}</td></tr></table></div>";
}
if (RemovedProperties.Any())
{
rpDescription = $"<div class=\"removedproperties\">{string.Join("; ", RemovedProperties.Select(rp => rp.Key))}</div>";
}
return
$"<h3>{StartedEventArgs.ProjectFile}</h3><br />{upDescription}{rpDescription}";
}
public string AnnotatedName
{
get => $"<span class=\"projectdescription\">{ProjectInstanceId}: <span class=\"shortfilename\">{Path.GetFileName(StartedEventArgs.ProjectFile)}</span><span class=\"tooltiptext\">{ToHtml()}</span></span>";
}
public string ProjectIdLink
{
get => $"<a class=\"linktoproject\" onclick=\"show({ParentProjectInstanceId})\">{ParentProjectInstanceId}</a>";
}
}
}