Skip to content

Commit

Permalink
Address CR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed May 14, 2024
1 parent db1420d commit c1ce415
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 54 deletions.

This file was deleted.

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}"";
}}
}}");
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="DotnetProductVersionInfoGenerator.cs" />
<Compile Include="ProductVersionInfoGenerator.cs" />
<Compile Include="EventSourceGenerator.cs" />
<Compile Include="EventSourceGenerator.Emitter.cs" />
<Compile Include="EventSourceGenerator.Parser.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2783,7 +2783,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="$(Version).versionstring" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;

Expand Down Expand Up @@ -201,8 +200,6 @@ public static OperatingSystem OSVersion
}
}

public static Version Version => Version.Parse(ProductVersionWithoutLabel);

public static string StackTrace
{
[MethodImpl(MethodImplOptions.NoInlining)] // Prevent inlining from affecting where the stacktrace starts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ public static partial class RuntimeInformation
{
private static string? s_runtimeIdentifier;

/// <summary>
/// Gets the name of the .NET installation on which an app is running.
/// </summary>
public static string FrameworkDescription { get; } = ".NET " + Environment.ProductVersionWithLabel;

/// <summary>
/// Returns an opaque string that identifies the platform on which an app is running.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(StabilizePackageVersion)' == 'true'">$(DefineConstants);STABILIZE_PACKAGE_VERSION</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="CheckArchitectureTests.cs" />
Expand Down

0 comments on commit c1ce415

Please sign in to comment.