Skip to content
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
58aeab6
Add telemetry logger support for API-based MSBuild usage
Copilot Sep 30, 2025
0b8fb6f
Add tests for ProjectInstanceExtensions telemetry logger creation
Copilot Sep 30, 2025
c37c61a
Fix telemetry logger to use distributed logging pattern with central …
Copilot Sep 30, 2025
1dc7f54
Fix ForwardingLoggerRecord to use central logger instance with forwar…
Copilot Sep 30, 2025
c201734
Share telemetry central logger instance between ProjectCollection and…
Copilot Sep 30, 2025
6d409d6
Add integration test for telemetry logger receiving events from API-b…
Copilot Sep 30, 2025
51f1399
Add telemetry logger support to VirtualProjectBuildingCommand
Copilot Oct 1, 2025
9343a69
Add telemetry logger support to PackageAddCommand for project evaluation
Copilot Oct 1, 2025
65f60f0
Add BannedApiAnalyzer to prevent direct MSBuild API usage without tel…
Copilot Nov 4, 2025
102371a
Scope BannedApiAnalyzer to src/Cli and fix all ProjectCollection viol…
Copilot Nov 4, 2025
3cd34a8
Use version property for BannedApiAnalyzers and update copilot-instru…
Copilot Nov 7, 2025
3093c60
Remove formatting-only changes to reduce PR noise
Copilot Nov 20, 2025
31e17b7
Restore BuildFinished event registration outside telemetry check
Copilot Nov 20, 2025
6eb6064
Revert accidental removal of functional code in TestCommand and telem…
Copilot Nov 20, 2025
243ad7f
react to changes post-rebase
baronfel Nov 21, 2025
151ef1a
Add unification plan document
baronfel Nov 23, 2025
bb53470
update local build instructions for copilot
baronfel Nov 23, 2025
ef5751b
big giant refactor towards more explicit types
baronfel Nov 24, 2025
5825147
Update some RunCommand infrastructure
baronfel Nov 25, 2025
6de6502
Tweak
baronfel Nov 25, 2025
ea3fc88
a lot more consolidation
baronfel Nov 25, 2025
ea27e91
finally plumb through centralizing on DotNetProject
baronfel Nov 29, 2025
4540b6a
update runcommand target framework selection to use evaluator
baronfel Nov 30, 2025
d3b9d3d
react to rebase
baronfel Dec 5, 2025
d2a96eb
prevent some duplicate loads when using the raw methods of the evaluator
baronfel Dec 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for ProjectInstanceExtensions telemetry logger creation
Co-authored-by: baronfel <[email protected]>
  • Loading branch information
Copilot and baronfel committed Dec 5, 2025
commit 0b8fb6f0aed80ab67e12c48c51b33ae5f14488f3
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using Microsoft.Build.Execution;
using Microsoft.DotNet.Cli.Extensions;
using Microsoft.DotNet.Cli.Telemetry;

namespace Microsoft.DotNet.Cli.MSBuild.Tests;

public class GivenProjectInstanceExtensions
{
[Fact]
public void CreateTelemetryLoggers_WhenTelemetryDisabled_ReturnsNull()
{
// Ensure telemetry is disabled
Telemetry.Telemetry.CurrentSessionId = null;

var loggers = ProjectInstanceExtensions.CreateTelemetryLoggers();

loggers.Should().BeNull();
}

[Fact]
public void CreateTelemetryLoggers_WhenTelemetryEnabled_ReturnsLoggers()
{
// Enable telemetry with a session ID
var originalSessionId = Telemetry.Telemetry.CurrentSessionId;
try
{
Telemetry.Telemetry.CurrentSessionId = Guid.NewGuid().ToString();

var loggers = ProjectInstanceExtensions.CreateTelemetryLoggers();

loggers.Should().NotBeNull();
loggers.Should().HaveCount(1);
loggers[0].Should().BeOfType<Commands.MSBuild.MSBuildLogger>();
}
finally
{
// Restore original session ID
Telemetry.Telemetry.CurrentSessionId = originalSessionId;
}
}

[Fact]
public void BuildWithTelemetry_WhenTelemetryDisabled_CallsBuildWithoutTelemetryLogger()
{
// This is a basic smoke test to ensure the extension method doesn't throw
// We can't easily test the actual build without setting up a full project

// Ensure telemetry is disabled
Telemetry.Telemetry.CurrentSessionId = null;

// CreateTelemetryLoggers should return null when telemetry is disabled
var loggers = ProjectInstanceExtensions.CreateTelemetryLoggers();
loggers.Should().BeNull();
}

[Fact]
public void BuildWithTelemetry_WhenTelemetryEnabled_CreatesTelemetryLogger()
{
// Enable telemetry with a session ID
var originalSessionId = Telemetry.Telemetry.CurrentSessionId;
try
{
Telemetry.Telemetry.CurrentSessionId = Guid.NewGuid().ToString();

// CreateTelemetryLoggers should return logger when telemetry is enabled
var loggers = ProjectInstanceExtensions.CreateTelemetryLoggers();
loggers.Should().NotBeNull();
loggers.Should().HaveCount(1);
}
finally
{
// Restore original session ID
Telemetry.Telemetry.CurrentSessionId = originalSessionId;
}
}
}