Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct product version in SPC in servicing #110980

Merged
merged 4 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
<!-- This prevents the default MsBuild targets from referencing System.Core.dll -->
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
<RuntimeMetadataVersion>v4.0.30319</RuntimeMetadataVersion>
<!-- Override InformationalVersion during servicing as it's returned via public api. -->
<InformationalVersion Condition="'$(PreReleaseVersionLabel)' == 'servicing'">$(ProductVersion)</InformationalVersion>
<InformationalVersion Condition="'$(StabilizePackageVersion)' == 'true'">$(ProductVersion)</InformationalVersion>
<NoWarn>$(NoWarn),0419,0649</NoWarn>
<Nullable>enable</Nullable>

Expand Down Expand Up @@ -302,6 +299,7 @@

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)\System.Private.CoreLib\gen\System.Private.CoreLib.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<CompilerVisibleProperty Include="InformationalVersion" />
</ItemGroup>

<Import Project="CreateRuntimeRootILLinkDescriptorFile.targets" />
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/nativeaot/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<!-- This prevents the default MsBuild targets from referencing System.Core.dll -->
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
<RuntimeMetadataVersion>v4.0.30319</RuntimeMetadataVersion>
<!-- Override InformationalVersion during servicing as it's returned via public api. -->
<InformationalVersion Condition="'$(PreReleaseVersionLabel)' == 'servicing'">$(ProductVersion)</InformationalVersion>
<InformationalVersion Condition="'$(StabilizePackageVersion)' == 'true'">$(ProductVersion)</InformationalVersion>
<NoWarn>$(NoWarn),0419,0649</NoWarn>

<!-- Disable nullability-related warnings -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)\System.Private.CoreLib\gen\System.Private.CoreLib.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<CompilerVisibleProperty Include="InformationalVersion" />
</ItemGroup>

<!-- Setup eventing file generation -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ public partial class ProductVersionInfoGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterPostInitializationOutput(ctx =>
{
string? informationalVersion = typeof(ProductVersionInfoGenerator).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
var informationalVersionProvider = context.AnalyzerConfigOptionsProvider.Select((options, _) =>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var informationalVersionProvider = context.AnalyzerConfigOptionsProvider.Select((options, _) =>
string informationalVersionProvider = context.AnalyzerConfigOptionsProvider.Select((options, _) =>

Nit: Repo coding conventions

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

ah sorry, I missed that this was about the coding conventions: #110997

options.GlobalOptions.TryGetValue("build_property.InformationalVersion", out string? ver) ? ver : null);

context.RegisterSourceOutput(informationalVersionProvider, (ctx, 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]);
string environmentVersion = Version.Parse(productVersion.Split('-')[0]).ToString();

#if STABILIZE_PACKAGE_VERSION
string frameworkDescriptionVersion = environmentVersion;
#else
string frameworkDescriptionVersion = productVersion;
#endif

ctx.AddSource("ProductVersionInfo.g.cs", $@"// <auto-generated/>

Expand All @@ -34,7 +41,7 @@ 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.ToString().Replace(".", ", ")});
public static Version Version => new Version({environmentVersion.Replace(".", ", ")});
}}
}}

Expand All @@ -45,7 +52,7 @@ 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}"";
public static string FrameworkDescription => "".NET {frameworkDescriptionVersion}"";
}}
}}");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>$(NoWarn);CS3001</NoWarn>
</PropertyGroup>
<PropertyGroup>
<DefineConstants Condition="'$(StabilizePackageVersion)' == 'true'">$(DefineConstants);STABILIZE_PACKAGE_VERSION</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="ProductVersionInfoGenerator.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
<!-- These prevent the default MsBuild targets from referencing System.dll and mscorlib.dll -->
<ExcludeMscorlibFacade>true</ExcludeMscorlibFacade>
<RuntimeMetadataVersion>v4.0.30319</RuntimeMetadataVersion>
<!-- Override InformationalVersion during servicing as it's returned via public api. -->
<InformationalVersion Condition="'$(PreReleaseVersionLabel)' == 'servicing'">$(ProductVersion)</InformationalVersion>
<InformationalVersion Condition="'$(StabilizePackageVersion)' == 'true'">$(ProductVersion)</InformationalVersion>
<NoWarn>$(NoWarn),0419,0649</NoWarn>
<Nullable>enable</Nullable>

Expand Down Expand Up @@ -301,6 +298,7 @@

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)\System.Private.CoreLib\gen\System.Private.CoreLib.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<CompilerVisibleProperty Include="InformationalVersion" />
</ItemGroup>

<Target Name="CopyCoreLibToBinDir" AfterTargets="Build">
Expand Down
Loading