Skip to content

Conversation

evgenyfedorov2
Copy link
Member

@evgenyfedorov2 evgenyfedorov2 commented Jul 17, 2025

Adding a brand new component - Build metadata, which automatically grabs build information from the CI/CD pipelines, deserializes it into a strong type BuildMetadata and registers it in Dependency Injection container as IOptions<BuildMetadata>.
The component uses source generation to collect build information and immediately express it via C# code.

Initially, only GitHub Actions and Azure DevOps are supported

Microsoft Reviewers: Open in CodeFlow

@dariusclay
Copy link
Member

I love porting until I realize my commit history is lost. 🤣

/// Gets or sets the build time in sortable date/time pattern.
/// This is the time the BuildMetadataGenerator was run.
/// </summary>
public string? BuildDateTime { get; set; }
Copy link

Choose a reason for hiding this comment

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

Should BuildDateTime, BuildNumber and BuildId be removed or be optional, hear me out...

A good practice in dotnet is reproducible builds, having source info like repository url, source commit etc... is fine because that would be consistent and considered an input to the build (albeit implicitly), but certainly timestamps would break this practice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, thank you for the comment. Need to think about it

// Azure DevOps environment variables: https://learn.microsoft.com/azure/devops/pipelines/build/variables#build-variables-devops-services
internal static string? AzureBuildId = Environment.GetEnvironmentVariable("Build_BuildId");
internal static string? AzureBuildNumber = Environment.GetEnvironmentVariable("Build_BuildNumber");
internal static string? AzureSourceBranchName = Environment.GetEnvironmentVariable("Build_SourceBranchName");
Copy link

Choose a reason for hiding this comment

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

Couldn't this alternatively be fetched by the InitializeSourceControlInformation and related targets in MSBuild that are used for SourceLink, that way this would work for local builds as well as CI.

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