1+ # Creates a Version.Overrides.props file to override version components for the workload set creation.
2+
3+ # $createTestWorkloadSet:
4+ # - If $true, adds PreReleaseVersionIteration overrides for creating a test workload set.
5+ # - If $false, does not add any PreReleaseVersionIteration overrides.
6+ # $versionSdkMinor: Adds the VersionSdkMinor property to the Version.Overrides.props file with the provided value.
7+ # - Example Value: '2'
8+ # $versionFeature: Adds the VersionFeature property to the Version.Overrides.props file with the provided value.
9+ # - Example Value: '01'
10+ # $versionPatch: Adds the VersionPatch property to the Version.Overrides.props file with the provided value.
11+ # - Example Value: '4'
12+ # $preReleaseVersionLabel: Adds the PreReleaseVersionLabel property to the Version.Overrides.props file with the provided value.
13+ # - Example Value: 'preview'
14+ # $preReleaseVersionIteration: Adds the PreReleaseVersionIteration property to the Version.Overrides.props file with the provided value.
15+ # - Example Value: '1'
16+
17+ param ([bool ] $createTestWorkloadSet = $false , [string ] $versionSdkMinor = ' |default|' , [string ] $versionFeature = ' |default|' , [string ] $versionPatch = ' |default|' , [string ] $preReleaseVersionLabel = ' |default|' , [string ] $preReleaseVersionIteration = ' |default|' )
18+
19+ $containsNonDefault = ($sdkVersionMinor , $versionFeature , $versionPatch , $preReleaseVersionLabel , $preReleaseVersionIteration | Where-Object { $_ -ne ' |default|' }) -ne $null
20+
21+ if (-not $containsNonDefault -and -not $createTestWorkloadSet ) {
22+ Write-Host ' No version overrides to apply.'
23+ exit 0
24+ }
25+
26+ $xmlDoc = New-Object System.Xml.XmlDocument
27+ $project = $xmlDoc.CreateElement (' Project' )
28+ $propertyGroup1 = $xmlDoc.CreateElement (' PropertyGroup' )
29+
30+ if ($versionSdkMinor -ne ' |default|' ) {
31+ $versionSdkMinorElem = $xmlDoc.CreateElement (' VersionSdkMinor' )
32+ $versionSdkMinorElem.InnerText = $versionSdkMinor
33+ $null = $propertyGroup1.AppendChild ($versionSdkMinorElem )
34+ Write-Host " Setting VersionSdkMinor to $versionSdkMinor ."
35+ }
36+
37+ if ($versionFeature -ne ' |default|' ) {
38+ $versionFeatureElem = $xmlDoc.CreateElement (' VersionFeature' )
39+ $versionFeatureElem.InnerText = $versionFeature
40+ $null = $propertyGroup1.AppendChild ($versionFeatureElem )
41+ Write-Host " Setting VersionFeature to $versionFeature ."
42+ }
43+
44+ if ($versionPatch -ne ' |default|' ) {
45+ $versionPatchElem = $xmlDoc.CreateElement (' VersionPatch' )
46+ $versionPatchElem.InnerText = $versionPatch
47+ $null = $propertyGroup1.AppendChild ($versionPatchElem )
48+ Write-Host " Setting VersionPatch to $versionPatch ."
49+ }
50+
51+ if ($preReleaseVersionLabel -ne ' |default|' ) {
52+ $preReleaseVersionLabelElem = $xmlDoc.CreateElement (' PreReleaseVersionLabel' )
53+ $preReleaseVersionLabelElem.InnerText = $preReleaseVersionLabel
54+ $null = $propertyGroup1.AppendChild ($preReleaseVersionLabelElem )
55+ Write-Host " Setting PreReleaseVersionLabel to $preReleaseVersionLabel ."
56+ }
57+
58+ if ($preReleaseVersionIteration -ne ' |default|' ) {
59+ $preReleaseVersionIterationElem = $xmlDoc.CreateElement (' PreReleaseVersionIteration' )
60+ $null = $preReleaseVersionIterationElem.SetAttribute (' Condition' , " '`$ (StabilizePackageVersion)' != 'true'" )
61+ $preReleaseVersionIterationElem.InnerText = $preReleaseVersionIteration
62+ $null = $propertyGroup1.AppendChild ($preReleaseVersionIterationElem )
63+ Write-Host " Setting PreReleaseVersionIteration to $preReleaseVersionIteration ."
64+ }
65+
66+ $null = $project.AppendChild ($propertyGroup1 )
67+ $propertyGroup2 = $xmlDoc.CreateElement (' PropertyGroup' )
68+
69+ $versionPrefix = $xmlDoc.CreateElement (' VersionPrefix' )
70+ $versionPrefix.InnerText = ' $(VersionMajor).$(VersionSdkMinor)$(VersionFeature).$(VersionPatch)'
71+ $null = $propertyGroup2.AppendChild ($versionPrefix )
72+
73+ $workloadsVersion1 = $xmlDoc.CreateElement (' WorkloadsVersion' )
74+ $workloadsVersion1.InnerText = ' $(VersionMajor).$(VersionMinor).$(VersionSdkMinor)$(VersionFeature)'
75+ $null = $propertyGroup2.AppendChild ($workloadsVersion1 )
76+
77+ $workloadsVersion2 = $xmlDoc.CreateElement (' WorkloadsVersion' )
78+ $null = $workloadsVersion2.SetAttribute (' Condition' , " '`$ (StabilizePackageVersion)' == 'true' and '`$ (VersionPatch)' != '0'" )
79+ $workloadsVersion2.InnerText = ' $(WorkloadsVersion).$(VersionPatch)'
80+ $null = $propertyGroup2.AppendChild ($workloadsVersion2 )
81+
82+ $sdkFeatureBand1 = $xmlDoc.CreateElement (' SdkFeatureBand' )
83+ $sdkFeatureBand1.InnerText = ' $(VersionMajor).$(VersionMinor).$(VersionSdkMinor)00'
84+ $null = $propertyGroup2.AppendChild ($sdkFeatureBand1 )
85+
86+ $sdkFeatureBand2 = $xmlDoc.CreateElement (' SdkFeatureBand' )
87+ $null = $sdkFeatureBand2.SetAttribute (' Condition' , " '`$ (StabilizePackageVersion)' != 'true' and '`$ (PreReleaseVersionLabel)' != 'servicing'" )
88+ $sdkFeatureBand2.InnerText = ' $(SdkFeatureBand)-$(PreReleaseVersionLabel).$(PreReleaseVersionIteration)'
89+ $null = $propertyGroup2.AppendChild ($sdkFeatureBand2 )
90+
91+ if ($createTestWorkloadSet ) {
92+ $preReleaseVersionIteration1 = $xmlDoc.CreateElement (' PreReleaseVersionIteration' )
93+ $null = $preReleaseVersionIteration1.SetAttribute (' Condition' , " '`$ (PreReleaseVersionLabel)' != 'servicing'" )
94+ $preReleaseVersionIteration1.InnerText = ' $(PreReleaseVersionIteration).0'
95+ $null = $propertyGroup2.AppendChild ($preReleaseVersionIteration1 )
96+
97+ $preReleaseVersionIteration2 = $xmlDoc.CreateElement (' PreReleaseVersionIteration' )
98+ $null = $preReleaseVersionIteration2.SetAttribute (' Condition' , " '`$ (PreReleaseVersionLabel)' == 'servicing'" )
99+ $preReleaseVersionIteration2.InnerText = ' 0'
100+ $null = $propertyGroup2.AppendChild ($preReleaseVersionIteration2 )
101+ Write-Host ' Setting PreReleaseVersionIteration for test workload set.'
102+ }
103+
104+ $null = $project.AppendChild ($propertyGroup2 )
105+ $null = $xmlDoc.AppendChild ($project )
106+
107+ $versionOverridesPath = Join-Path - Path $PSScriptRoot - ChildPath ' Version.Overrides.props'
108+ $null = $xmlDoc.Save ($versionOverridesPath )
0 commit comments