Scripts/UpdateVersion.ps1
# UpdateVersion.ps1 function Set-DataverseSolutionVersion { param( [string] [Parameter(Mandatory = $true)] $SolutionVersion, [string] [Parameter(Mandatory = $true)] $SolutionName, [System.Collections.Generic.List[System.Object]] [Parameter(Mandatory = $false)] $Patches ) try { Write-Host "Updating Solution version for $SolutionName" $Date = Get-Date $Date = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($Date, "UTC") $patchVersions = @() try { $versionsFile = Get-Content -Path "$global:devops_projectLocation\$SolutionName\$SolutionName.version" -ErrorAction SilentlyContinue | ConvertFrom-Json $versionsFile = @($versionsFile[0]) } catch { } # If there are no Patches if (!$Patches) { # 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]@{SolutionFriendlyName = $SolutionFriendlyName ; SolutionName = $SolutionName; Version = $newVersion.ToString() ; }) ConvertTo-Json -Depth 4 $solutionTracker | Format-Json | Out-FileUtf8NoBom "$global:devops_projectLocation\$SolutionName\$SolutionName.version" Write-Host $verUpdated } else { if ($global:devops_projectFile.IncrementLatestPatchOnExport -eq "True") { $LatestPatch = $Patches[$Patches.Count - 1] $newVersion = "{0}.{1}{2}.{3}.{4}" -f ([version]$LatestPatch.version).Major, (Get-Date($Date) -UFormat %y), (Get-Date($Date) -UFormat %j).PadLeft(3, '0'), ([version]$LatestPatch.version).Build , (Get-Date($Date) -UFormat %H%M) $verUpdated = Set-CrmSolutionVersionNumber -conn $conn -SolutionName $LatestPatch.uniquename -VersionNumber $newVersion $Patches[$Patches.Count - 1].version = $newVersion Write-Host "Updated version number of the latest patch," $LatestPatch.uniquename } foreach ($PatchSolution in $Patches) { $SolutionId = $PatchSolution.solutionid $SolutionFriendlyName = $PatchSolution.friendlyname $SolutionName = $PatchSolution.uniquename $SolutionVersion = $PatchSolution.version Write-Host "Patch found:" $SolutionId "-" $SolutionName "-" $SolutionVersion "("$SolutionFriendlyName")" $theVersion = [version]$SolutionVersion $newVersion = "{0}.{1}.{2}.{3}{4}" -f $theVersion.Major, $theVersion.Minor, $theVersion.Build, $theVersion.MajorRevision, $theVersion.MinorRevision $global:devops_newVersion = $newVersion $patchTracker = @([ordered]@{SolutionFriendlyName = $SolutionFriendlyName ; SolutionName = $SolutionName; Version = $newVersion.ToString() ; }) $patchVersions += $patchTracker } $versionsFile += $patchVersions ConvertTo-Json -Depth 4 $versionsFile | Format-Json | Out-FileUtf8NoBom $global:devops_projectLocation\$global:devops_SolutionName\$global:devops_SolutionName.version } } catch { Write-Host $_ pause } } |