Scripts/UpdateVersion.ps1
# UpdateVersion.ps1 function Set-DataverseSolutionVersion { try { $message = "Updating Solution version for $global:devops_SolutionName" Write-Host $message $Date = Get-Date $Date = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($Date,"UTC") $patchVersions = @() Write-Host "" try { $versionsFile = Get-Content -Path $global:devops_projectLocation\$global:devops_SolutionName\$global:devops_SolutionName.version -ErrorAction SilentlyContinue | ConvertFrom-Json $versionsFile = @($versionsFile[0]) } catch { } foreach ($PatchSolution in $PatchQuery.CrmRecords) { $SolutionId = $PatchSolution.solutionid $SolutionName = $PatchSolution.uniquename $SolutionVersion = $PatchSolution.version Write-Host "Patch found:" $SolutionId "-" $SolutionName "-" $SolutionVersion $theVersion = [version]$SolutionVersion $newVersion = "{0}.{1}.{2}.{3}" -f $theVersion.Major, $theVersion.Minor, $theVersion.Build , ($theVersion.Revision + 1) $global:devops_newVersion = $newVersion $verUpdated = Set-CrmSolutionVersionNumber -conn $conn -SolutionName $SolutionName -VersionNumber $newVersion $patchTracker = @([ordered]@{SolutionName = $SolutionName; Version = $newVersion.ToString() ; }) $patchVersions += $patchTracker Write-Host $verUpdated } if ($PatchQuery.CrmRecords.Count -gt 0) { $versionsFile += $patchVersions ConvertTo-Json -Depth 4 $versionsFile | Format-Json | Out-FileUtf8NoBom $global:devops_projectLocation\$global:devops_SolutionName\$global:devops_SolutionName.version } If (!$PatchQuery.CrmRecords) { #Major.Minor.Build.Revision = TargetProductionDrop.Year+DayofYear.PatchNumber.BuildTime $theVersion = [version]$SolutionVersion $newVersion = "{0}.{1}{2}.{3}.{4}" -f $theVersion.Major, (Get-Date($Date) -UFormat %y), (Get-Date($Date) -UFormat %j).PadLeft(3, '0'), $theVersion.Build , (Get-Date($Date) -UFormat %H%M) $global:devops_newVersion = $newVersion $verUpdated = Set-CrmSolutionVersionNumber -conn $conn -SolutionName $SolutionName -VersionNumber $newVersion $solutionTracker = @([ordered]@{SolutionName = $SolutionName; Version = $newVersion.ToString() ; }) ConvertTo-Json -Depth 4 $solutionTracker | Format-Json | Out-FileUtf8NoBom $global:devops_projectLocation\$global:devops_SolutionName\$global:devops_SolutionName.version Write-Host $verUpdated } } catch { Write-Host $_ pause } finally { } } |