-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
58 additions
and
54 deletions.
There are no files selected for viewing
42 changes: 0 additions & 42 deletions
42
src/libraries/System.Private.CoreLib/gen/DotnetProductVersionInfoGenerator.cs
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/libraries/System.Private.CoreLib/gen/ProductVersionInfoGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Reflection; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Generators | ||
{ | ||
[Generator] | ||
public partial class ProductVersionInfoGenerator : IIncrementalGenerator | ||
{ | ||
public void Initialize(IncrementalGeneratorInitializationContext context) | ||
{ | ||
context.RegisterPostInitializationOutput(ctx => | ||
{ | ||
string? informationalVersion = typeof(ProductVersionInfoGenerator).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion; | ||
// strip semver metadata (git hash) followed by + sign | ||
string? productVersion = informationalVersion?.Split('+')?[0]; | ||
if (string.IsNullOrEmpty(productVersion)) | ||
throw new InvalidOperationException($"Unable to obtain product version at build-time."); | ||
// strip semver prerelease label followed by - sign for Environment.Version | ||
Version versionObject = Version.Parse(productVersion.Split('-')[0]); | ||
ctx.AddSource("ProductVersionInfo.g.cs", $@"// <auto-generated/> | ||
namespace System | ||
{{ | ||
public static partial class Environment | ||
{{ | ||
/// <summary> | ||
/// Gets a version consisting of the major, minor, build, and revision numbers of the common language runtime. | ||
/// </summary> | ||
public static Version Version => new Version({versionObject.Major}, {versionObject.Minor}, {versionObject.Build}); | ||
}} | ||
}} | ||
namespace System.Runtime.InteropServices | ||
{{ | ||
public static partial class RuntimeInformation | ||
{{ | ||
/// <summary> | ||
/// Gets the name of the .NET installation on which an app is running. | ||
/// </summary> | ||
public static string FrameworkDescription => "".NET {productVersion}""; | ||
}} | ||
}}"); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters