Skip to content

Commit 7150dc9

Browse files
authored
Adding tracking of properties with relevant events. (#4461)
This change introduces opt-in functionality that will track property usage and generate three events: Environment Variables Read (new) Uninitialized Properties Read (new) Property Reassigned (already exists) Opt-in for these events is via the environment variable, MSBuildLogPropertyTracking.
1 parent 1a8376a commit 7150dc9

36 files changed

Lines changed: 1403 additions & 124 deletions

ref/Microsoft.Build.Framework/net/Microsoft.Build.Framework.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ protected CustomBuildEventArgs(string message, string helpKeyword, string sender
143143
protected CustomBuildEventArgs(string message, string helpKeyword, string senderName, System.DateTime eventTimestamp, params object[] messageArgs) { }
144144
}
145145
public delegate void CustomBuildEventHandler(object sender, Microsoft.Build.Framework.CustomBuildEventArgs e);
146+
public partial class EnvironmentVariableReadEventArgs : Microsoft.Build.Framework.BuildMessageEventArgs
147+
{
148+
public EnvironmentVariableReadEventArgs() { }
149+
public EnvironmentVariableReadEventArgs(string environmentVariableName, string message, string helpKeyword=null, string senderName=null, Microsoft.Build.Framework.MessageImportance importance=(Microsoft.Build.Framework.MessageImportance)(2)) { }
150+
public string EnvironmentVariableName { get { throw null; } set { } }
151+
}
146152
public partial class ExternalProjectFinishedEventArgs : Microsoft.Build.Framework.CustomBuildEventArgs
147153
{
148154
protected ExternalProjectFinishedEventArgs() { }
@@ -402,6 +408,23 @@ public ProjectStartedEventArgs(string message, string helpKeyword, string projec
402408
public string ToolsVersion { get { throw null; } }
403409
}
404410
public delegate void ProjectStartedEventHandler(object sender, Microsoft.Build.Framework.ProjectStartedEventArgs e);
411+
public partial class PropertyInitialValueSetEventArgs : Microsoft.Build.Framework.BuildMessageEventArgs
412+
{
413+
public PropertyInitialValueSetEventArgs() { }
414+
public PropertyInitialValueSetEventArgs(string propertyName, string propertyValue, string propertySource, string message, string helpKeyword=null, string senderName=null, Microsoft.Build.Framework.MessageImportance importance=(Microsoft.Build.Framework.MessageImportance)(2)) { }
415+
public string PropertyName { get { throw null; } set { } }
416+
public string PropertySource { get { throw null; } set { } }
417+
public string PropertyValue { get { throw null; } set { } }
418+
}
419+
public partial class PropertyReassignmentEventArgs : Microsoft.Build.Framework.BuildMessageEventArgs
420+
{
421+
public PropertyReassignmentEventArgs() { }
422+
public PropertyReassignmentEventArgs(string propertyName, string previousValue, string newValue, string location, string message, string helpKeyword=null, string senderName=null, Microsoft.Build.Framework.MessageImportance importance=(Microsoft.Build.Framework.MessageImportance)(2)) { }
423+
public string Location { get { throw null; } set { } }
424+
public string NewValue { get { throw null; } set { } }
425+
public string PreviousValue { get { throw null; } set { } }
426+
public string PropertyName { get { throw null; } set { } }
427+
}
405428
public enum RegisteredTaskObjectLifetime
406429
{
407430
AppDomain = 1,
@@ -562,6 +585,12 @@ public TelemetryEventArgs() { }
562585
public System.Collections.Generic.IDictionary<string, string> Properties { get { throw null; } set { } }
563586
}
564587
public delegate void TelemetryEventHandler(object sender, Microsoft.Build.Framework.TelemetryEventArgs e);
588+
public partial class UninitializedPropertyReadEventArgs : Microsoft.Build.Framework.BuildMessageEventArgs
589+
{
590+
public UninitializedPropertyReadEventArgs() { }
591+
public UninitializedPropertyReadEventArgs(string propertyName, string message, string helpKeyword=null, string senderName=null, Microsoft.Build.Framework.MessageImportance importance=(Microsoft.Build.Framework.MessageImportance)(2)) { }
592+
public string PropertyName { get { throw null; } set { } }
593+
}
565594
}
566595
namespace Microsoft.Build.Framework.Profiler
567596
{

ref/Microsoft.Build.Framework/netstandard/Microsoft.Build.Framework.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ protected CustomBuildEventArgs(string message, string helpKeyword, string sender
143143
protected CustomBuildEventArgs(string message, string helpKeyword, string senderName, System.DateTime eventTimestamp, params object[] messageArgs) { }
144144
}
145145
public delegate void CustomBuildEventHandler(object sender, Microsoft.Build.Framework.CustomBuildEventArgs e);
146+
public partial class EnvironmentVariableReadEventArgs : Microsoft.Build.Framework.BuildMessageEventArgs
147+
{
148+
public EnvironmentVariableReadEventArgs() { }
149+
public EnvironmentVariableReadEventArgs(string environmentVariableName, string message, string helpKeyword=null, string senderName=null, Microsoft.Build.Framework.MessageImportance importance=(Microsoft.Build.Framework.MessageImportance)(2)) { }
150+
public string EnvironmentVariableName { get { throw null; } set { } }
151+
}
146152
public partial class ExternalProjectFinishedEventArgs : Microsoft.Build.Framework.CustomBuildEventArgs
147153
{
148154
protected ExternalProjectFinishedEventArgs() { }
@@ -401,6 +407,23 @@ public ProjectStartedEventArgs(string message, string helpKeyword, string projec
401407
public string ToolsVersion { get { throw null; } }
402408
}
403409
public delegate void ProjectStartedEventHandler(object sender, Microsoft.Build.Framework.ProjectStartedEventArgs e);
410+
public partial class PropertyInitialValueSetEventArgs : Microsoft.Build.Framework.BuildMessageEventArgs
411+
{
412+
public PropertyInitialValueSetEventArgs() { }
413+
public PropertyInitialValueSetEventArgs(string propertyName, string propertyValue, string propertySource, string message, string helpKeyword=null, string senderName=null, Microsoft.Build.Framework.MessageImportance importance=(Microsoft.Build.Framework.MessageImportance)(2)) { }
414+
public string PropertyName { get { throw null; } set { } }
415+
public string PropertySource { get { throw null; } set { } }
416+
public string PropertyValue { get { throw null; } set { } }
417+
}
418+
public partial class PropertyReassignmentEventArgs : Microsoft.Build.Framework.BuildMessageEventArgs
419+
{
420+
public PropertyReassignmentEventArgs() { }
421+
public PropertyReassignmentEventArgs(string propertyName, string previousValue, string newValue, string location, string message, string helpKeyword=null, string senderName=null, Microsoft.Build.Framework.MessageImportance importance=(Microsoft.Build.Framework.MessageImportance)(2)) { }
422+
public string Location { get { throw null; } set { } }
423+
public string NewValue { get { throw null; } set { } }
424+
public string PreviousValue { get { throw null; } set { } }
425+
public string PropertyName { get { throw null; } set { } }
426+
}
404427
public enum RegisteredTaskObjectLifetime
405428
{
406429
AppDomain = 1,
@@ -561,6 +584,12 @@ public TelemetryEventArgs() { }
561584
public System.Collections.Generic.IDictionary<string, string> Properties { get { throw null; } set { } }
562585
}
563586
public delegate void TelemetryEventHandler(object sender, Microsoft.Build.Framework.TelemetryEventArgs e);
587+
public partial class UninitializedPropertyReadEventArgs : Microsoft.Build.Framework.BuildMessageEventArgs
588+
{
589+
public UninitializedPropertyReadEventArgs() { }
590+
public UninitializedPropertyReadEventArgs(string propertyName, string message, string helpKeyword=null, string senderName=null, Microsoft.Build.Framework.MessageImportance importance=(Microsoft.Build.Framework.MessageImportance)(2)) { }
591+
public string PropertyName { get { throw null; } set { } }
592+
}
564593
}
565594
namespace Microsoft.Build.Framework.Profiler
566595
{

src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,79 @@ public void RoundtripTargetSkippedEventArgs()
418418
e => e.BuildReason.ToString());
419419
}
420420

421+
[Fact]
422+
public void RoundTripEnvironmentVariableReadEventArgs()
423+
{
424+
var args = new EnvironmentVariableReadEventArgs(
425+
environmentVariableName: Guid.NewGuid().ToString(),
426+
message: Guid.NewGuid().ToString(),
427+
helpKeyword: Guid.NewGuid().ToString(),
428+
senderName: Guid.NewGuid().ToString());
429+
430+
Roundtrip(args,
431+
e => e.EnvironmentVariableName,
432+
e => e.Message,
433+
e => e.HelpKeyword,
434+
e => e.SenderName);
435+
}
436+
437+
[Fact]
438+
public void RoundTripPropertyReassignmentEventArgs()
439+
{
440+
var args = new PropertyReassignmentEventArgs(
441+
propertyName: Guid.NewGuid().ToString(),
442+
previousValue: Guid.NewGuid().ToString(),
443+
newValue: Guid.NewGuid().ToString(),
444+
location: Guid.NewGuid().ToString(),
445+
message: Guid.NewGuid().ToString(),
446+
helpKeyword: Guid.NewGuid().ToString(),
447+
senderName: Guid.NewGuid().ToString());
448+
449+
Roundtrip(args,
450+
e => e.PropertyName,
451+
e => e.PreviousValue,
452+
e => e.NewValue,
453+
e => e.Location,
454+
e => e.Message,
455+
e => e.HelpKeyword,
456+
e => e.SenderName);
457+
}
458+
459+
[Fact]
460+
public void UninitializedPropertyReadEventArgs()
461+
{
462+
var args = new UninitializedPropertyReadEventArgs(
463+
propertyName: Guid.NewGuid().ToString(),
464+
message: Guid.NewGuid().ToString(),
465+
helpKeyword: Guid.NewGuid().ToString(),
466+
senderName: Guid.NewGuid().ToString());
467+
468+
Roundtrip(args,
469+
e => e.PropertyName,
470+
e => e.Message,
471+
e => e.HelpKeyword,
472+
e => e.SenderName);
473+
}
474+
475+
[Fact]
476+
public void PropertyInitialValueEventArgs()
477+
{
478+
var args = new PropertyInitialValueSetEventArgs(
479+
propertyName: Guid.NewGuid().ToString(),
480+
propertyValue: Guid.NewGuid().ToString(),
481+
propertySource: Guid.NewGuid().ToString(),
482+
message: Guid.NewGuid().ToString(),
483+
helpKeyword: Guid.NewGuid().ToString(),
484+
senderName: Guid.NewGuid().ToString());
485+
486+
Roundtrip(args,
487+
e => e.PropertyName,
488+
e => e.PropertyValue,
489+
e => e.PropertySource,
490+
e => e.Message,
491+
e => e.HelpKeyword,
492+
e => e.SenderName);
493+
}
421494
[Fact]
422495
public void ReadingCorruptedStreamThrows()
423496
{

0 commit comments

Comments
 (0)