Created
May 16, 2024 20:33
-
-
Save wchesley/0c68d91730007a2fbbf5c6b0bfbfe373 to your computer and use it in GitHub Desktop.
Autoincrement Build and Revision number - .NET Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read the csproj file | |
[xml]$content = Get-Content './Relative/Path/To/csproj' | |
# Show initial version: | |
$initialVersion = $csproj.Project.PropertyGroup.Version | |
Write-Host "Initial Version: " $initialVersion | |
$spliteVersion = $initialVersion -Split "\." | |
Write-Host "Major:" $spliteVersion[0] | |
#Get the build number (number of days since November 1, 2023) | |
$baseDate = [datetime]"11/01/2023" | |
$currentDate = $( Get-Date ) | |
$interval = (NEW-TIMESPAN -Start $baseDate -End $currentDate) | |
$buildNumber = $interval.Days | |
#Get the revision number (number seconds (divided by two) into the day on which the compilation was performed) | |
$StartDate = [datetime]::Today | |
$EndDate = (GET-DATE) | |
$revisionNumber = [math]::Round((New-TimeSpan -Start $StartDate -End $EndDate).TotalSeconds / 2, 0) | |
#Final version number | |
$finalBuildVersion = "$( $spliteVersion[0] ).$( $spliteVersion[1] ).$( $buildNumber ).$( $revisionNumber )" | |
$csproj.Project.PropertyGroup.Version = $finalBuildVersion; | |
$csproj.Save('./Relative/Path/To/csproj'); | |
Write-Host "Major.Minor.Build.Revision" | |
Write-Host "Final build number: " $finalBuildVersion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment