4
4
#nullable disable
5
5
6
6
using NuGet . Frameworks ;
7
+ using NuGet . Versioning ;
7
8
8
9
namespace Microsoft . DotNet . Build . Tasks
9
10
{
@@ -12,7 +13,11 @@ namespace Microsoft.DotNet.Build.Tasks
12
13
/// the latest patches of different major versions are built entirely separately, and we want to have tests
13
14
/// on downlevel versions but we can't depend on the latest patches being available in test environments.
14
15
///
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.
16
21
/// </summary>
17
22
public sealed class OverrideAndCreateBundledNETCoreAppPackageVersion : Task
18
23
{
@@ -70,7 +75,26 @@ void UpdateItems(string elementName, string[] matchAttrs, string[] updateAttrs)
70
75
var v0 = item0 . Attribute ( updateAttr ) ? . Value ;
71
76
var v2 = item2 . Attribute ( updateAttr ) ? . Value ;
72
77
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
+ }
74
98
}
75
99
// Log if other metadata differs
76
100
foreach ( var attr in item2 . Attributes ( ) )
0 commit comments