Repository: PowerShell/PowerShell
File: src/System.Management.Automation/SourceGenerators/PSVersionInfoGenerator/PSVersionInfoGenerator.cs (C#)

Code before:
                };

                return options;
            });

            context.RegisterSourceOutput(buildOptionsProvider,
            static (context, buildOptions) =>
            {
                string gitCommitId = string.IsNullOrEmpty(buildOptions.ReleaseTag) ? buildOptions.GitDescribe : buildOptions.ReleaseTag;
                if (gitCommitId.StartsWith("v"))
                {
                    gitCommitId = gitCommitId.Substring(1);
                }

                var versions = ParsePSVersion(buildOptions.MainVersion);
                string result = string.Format(
                    CultureInfo.InvariantCulture,
                    SourceTemplate,
                    buildOptions.ProductVersion,
                    gitCommitId,
                    versions.major,
                    versions.minor,
                    versions.patch,
                    versions.preReleaseLabel);

                context.AddSource($"PSVersionInfo.g.cs", result);
            });
        }

        private struct BuildOptions
        {
            public string ProductVersion;
            public string MainVersion;
            public string GitDescribe;
            public string ReleaseTag;
        }

        // We must put "<auto-generated" on first line so that Roslyng analyzers skip the file.
        private const string SourceTemplate = @"// <auto-generated>
// This file is auto-generated by PSVersionInfoGenerator.
// </auto-generated>

namespace System.Management.Automation
{{
    public static partial class PSVersionInfo
    {{
        // Defined in 'PowerShell.Common.props' as 'ProductVersion'
        // Example:
        //  - when built from a commit:              ProductVersion = '7.3.0-preview.8 Commits: 29 SHA: 52c6b...'
        //  - when built from a preview release tag: ProductVersion = '7.3.0-preview.8 SHA: f1ec9...'
        //  - when built from a stable release tag:  ProductVersion = '7.3.0 SHA: f1ec9...'

Review comment (suggestion):
```suggestion
                context.AddSource("PSVersionInfo.g.cs", result);
```

Code after:
                    };

                    return options;
                });

            context.RegisterSourceOutput(
                buildOptionsProvider,
                static (context, buildOptions) =>
                {
                    string gitCommitId = string.IsNullOrEmpty(buildOptions.ReleaseTag) ? buildOptions.GitDescribe : buildOptions.ReleaseTag;
                    if (gitCommitId.StartsWith("v"))
                    {
                        gitCommitId = gitCommitId.Substring(1);
                    }

                    var versions = ParsePSVersion(buildOptions.MainVersion);
                    string result = string.Format(
                        CultureInfo.InvariantCulture,
                        SourceTemplate,
                        buildOptions.ProductVersion,
                        gitCommitId,
                        versions.major,
                        versions.minor,
                        versions.patch,
                        versions.preReleaseLabel);

                    // We must use specific file name suffix (*.g.cs,*.g, *.i.cs, *.generated.cs, *.designer.cs)
                    // so that Roslyn analyzers skip the file.
                    context.AddSource("PSVersionInfo.g.cs", result);
                });
        }

        private struct BuildOptions
        {
            public string ProductVersion;
            public string MainVersion;
            public string GitDescribe;
            public string ReleaseTag;
        }

        // We must put "<auto-generated" on first line so that Roslyng analyzers skip the file.
        private const string SourceTemplate = @"// <auto-generated>
// This file is auto-generated by PSVersionInfoGenerator.
// </auto-generated>

namespace System.Management.Automation
{{
    public static partial class PSVersionInfo
    {{
        // Defined in 'PowerShell.Common.props' as 'ProductVersion'
        // Example: