Skip to content

Commit 5a0ee7c

Browse files
committed
Use preview versions from stage2 instead of stage 0 for stage 2 bundled versions
1 parent c3f2e9f commit 5a0ee7c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/Tasks/sdk-tasks/OverrideAndCreateBundledNETCoreAppPackageVersion.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#nullable disable
55

66
using NuGet.Frameworks;
7+
using NuGet.Versioning;
78

89
namespace Microsoft.DotNet.Build.Tasks
910
{
@@ -12,7 +13,11 @@ namespace Microsoft.DotNet.Build.Tasks
1213
/// the latest patches of different major versions are built entirely separately, and we want to have tests
1314
/// on downlevel versions but we can't depend on the latest patches being available in test environments.
1415
///
15-
/// So we copy the version numbers from stage 0 for those downlevel versions.
16+
/// So we copy the version numbers from stage 0 for those downlevel versions.
17+
///
18+
/// However, if the stage 2 version is a preview version, we don't overwrite it. This is because in this case
19+
/// the version of .NET hasn't been released yet, so we want to use the later preview version. The preview
20+
/// versions should all be on the same NuGet feeds anyway.
1621
/// </summary>
1722
public sealed class OverrideAndCreateBundledNETCoreAppPackageVersion : Task
1823
{
@@ -70,7 +75,26 @@ void UpdateItems(string elementName, string[] matchAttrs, string[] updateAttrs)
7075
var v0 = item0.Attribute(updateAttr)?.Value;
7176
var v2 = item2.Attribute(updateAttr)?.Value;
7277
if (v0 != null && v2 != v0)
73-
item2.SetAttributeValue(updateAttr, v0);
78+
{
79+
bool isPreview = false;
80+
if (!string.IsNullOrEmpty(v2))
81+
{
82+
try
83+
{
84+
var nugetVersion = NuGetVersion.Parse(v2);
85+
isPreview = nugetVersion.IsPrerelease;
86+
}
87+
catch
88+
{
89+
// If parsing fails, treat as non-preview
90+
isPreview = false;
91+
}
92+
}
93+
if (!isPreview)
94+
{
95+
item2.SetAttributeValue(updateAttr, v0);
96+
}
97+
}
7498
}
7599
// Log if other metadata differs
76100
foreach (var attr in item2.Attributes())

0 commit comments

Comments
 (0)