Skip to content

Conversation

matouskozak
Copy link
Member

@matouskozak matouskozak commented Aug 31, 2025

Description

Adding properties (TargetPlatformIdentifier, UseMonoRuntime, PublishAot, Configuration) needed for mobile-related telemetry tracking to targetframeworkeval event.

Additionally, adding more publish-related (PublishTrimmed, PublishSelfContained, PublishReadyToRun, PublishReadyToRunComposite, PublishProtocol) properties to make targetframeworkeval the center piece for property tracking.

Sample Output Telemetry

{
    "EventName": "targetframeworkeval",
    "Properties": {
        "TargetFrameworkVersion": ".NETCoreApp,Version=v10.0",
        "RuntimeIdentifier": "android-arm64",
        "SelfContained": "true",
        "UseApphost": "false",
        "OutputType": "Library",
        "UseArtifactsOutput": "null",
        "ArtifactsPathLocationType": "null",
        "TargetPlatformIdentifier": "android",
        "UseMonoRuntime": "true",
        "PublishAot": "false",
        "PublishTrimmed": "null",
        "PublishSelfContained": "null",
        "PublishReadyToRun": "false",
        "PublishReadyToRunComposite": "false",
        "PublishProtocol": "null",
        "Configuration": "Debug"
    },
    "Timestamp": "2025-09-12T12:27:52.710113+01:00",
    "ThreadId": 12,
    "Message": null,
    "HelpKeyword": null,
    "SenderName": null,
    "BuildEventContext": {
        "EvaluationId": -1,
        "NodeId": 1,
        "TargetId": 45,
        "ProjectContextId": 15,
        "TaskId": 39,
        "ProjectInstanceId": 2,
        "SubmissionId": 0,
        "BuildRequestId": -2063244756
    }
}

Testing

Tested locally by installing android workload to .dotnet/dotnet and running the following tests:

Publish:

[CoreMSBuildOnlyTheory]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
public void It_collects_Mobile_properties_for_publish(string targetFramework)
{
    Type loggerType = typeof(LogTelemetryToStdOutForTest);
    var TelemetryTestLogger = new[]
        {
            "--property:TargetPlatformIdentifier=android",
            "--property:RuntimeIdentifier=android-arm64",
            "--property:UseMonoRuntime=true",
            "--property:PublishAot=false",
            $"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}"
        };

    var testProject = CreateTestProject(targetFramework, "MobileTelemetryPublishTest");
    var testProjectInstance = _testAssetsManager.CreateTestProject(testProject);
    var publishCommand = new PublishCommand(testProjectInstance);
    publishCommand.Execute(TelemetryTestLogger).StdOut.Should.Contain(...)

Build:

[CoreMSBuildOnlyFact]
public void It_collects_Mobile_properties_for_build()
{
    string targetFramework = ToolsetInfo.CurrentTargetFramework;
    var testProject = new TestProject()
    {
        Name = "MobileTelemetryBuildTest",
        TargetFrameworks = targetFramework,
    };
    Type loggerType = typeof(LogTelemetryToStdOutForTest);
    var telemetryArgs = new[]
        {
            "--property:TargetPlatformIdentifier=android",
            "--property:RuntimeIdentifier=android-arm64",
            "--property:UseMonoRuntime=false",
            "--property:PublishAot=false",
            $"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}"
        };
    var testAsset = _testAssetsManager.CreateTestProject(testProject);

    var buildCommand = new BuildCommand(testAsset);

    buildCommand
        .Execute(telemetryArgs)
        .StdOut.Should()
        .Contain(...)

Another testing was done by locally modified version of SDK, where I modified the .target files and verified that the mobile telemetry targets get executed for dotnet new android app.

Future Work

  • Add SessionId that allows pairing targetframeworkeval events with build/publish and other .NET CLI commands.

@matouskozak matouskozak added this to the 10.0.1xx milestone Aug 31, 2025
@matouskozak matouskozak self-assigned this Aug 31, 2025
Copy link
Contributor

This PR is targeting main, which is now for .NET 11-facing work. If you intended to target .NET 10, either retarget this PR to release/10.0.1xx or make sure you backport the change to release/10.0.1xx after merging. See #50394 for more details.

@matouskozak matouskozak marked this pull request as ready for review September 1, 2025 10:15
@Copilot Copilot AI review requested due to automatic review settings September 1, 2025 10:15
Copilot

This comment was marked as outdated.

@baronfel
Copy link
Member

baronfel commented Sep 2, 2025

Triage/proposal:

  • We should instead unify the current Publish properties and targetframeworkeval events into one combined data set
  • We need to add a new SessionId value because the existing telemetry-context one isn't being forwarded for some reason
  • We need clarity from @matouskozak's team about how you'd like to reason about multi-project and/or multi-TFM builds
    • We may be able to filter out transitive builds triggered by a top-level project if so.

@matouskozak matouskozak force-pushed the android-coreclr-telemetry branch from 7c601fd to cb3a23b Compare September 9, 2025 12:09
@matouskozak matouskozak requested a review from Copilot September 9, 2025 12:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds mobile telemetry collection for the Build target that captures platform-specific properties for Android, iOS, macCatalyst, and tvOS builds. The telemetry collects properties like target platform identifier, runtime identifier, mono runtime usage, and AOT/ReadyToRun configurations.

  • Extends existing target framework telemetry to include mobile-specific properties
  • Updates test expectations to include the new telemetry properties in assertions

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreAppForTelemetry.cs Updates test assertions to include new mobile telemetry properties in expected output
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.TargetFrameworkInference.targets Adds three new telemetry properties for mobile builds: TargetPlatformIdentifier, UseMonoRuntime, and PublishAot

@matouskozak matouskozak changed the title Add mobile telemetry hooks for Build target Add mobile-related properties to targetframeworkeval telemetry event Sep 9, 2025
Copy link
Member

@baronfel baronfel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but have a request for a few more properties so we can be ready to deprecate the PublishProperties event in the future.

@matouskozak matouskozak changed the title Add mobile-related properties to targetframeworkeval telemetry event Add more properties to targetframeworkeval telemetry event Sep 12, 2025
@dsplaisted
Copy link
Member

Note that this PR is targeting main. We'll either need to retarget it to release/10.0.1xx, or merge it to main and then backport.

Any preference? @matouskozak @baronfel

@baronfel
Copy link
Member

Since it's already green on this branch I'd just backport, to save more CI cycles

@dsplaisted dsplaisted merged commit f099c19 into dotnet:main Sep 12, 2025
27 checks passed
@dsplaisted
Copy link
Member

/backport to release/10.0.1xx

Copy link
Contributor

Started backporting to release/10.0.1xx: https://github.com/dotnet/sdk/actions/runs/17676204640

@baronfel
Copy link
Member

I added the documentation label as a marker that we have some work to do here before GA. most properties are already documented, we just need the new ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants