-
-
Save ElanHasson/5bb3f323bc63845847208ce55779305b to your computer and use it in GitHub Desktop.
Powershell script for generating a version number and inserting it into the csproj
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
param( | |
[Parameter(Mandatory = $true)] | |
[string] $csprojPath, | |
[Parameter(Mandatory = $true)] | |
[string] $newVersion | |
) | |
Write-Host "Starting process of generating new version number for the csproj" | |
foreach ($filePath in (Get-ChildItem -Path $csprojPath -Recurse)) { | |
Write-Host "Setting version of $filePath..." | |
$splitNumber = $newVersion.Split(".") | |
if ( $splitNumber.Count -eq 4 ) { | |
$majorNumber = $splitNumber[0] | |
$minorNumber = $splitNumber[1] | |
$revisionNumber = $splitNumber[3] | |
# I need to keep my build number under the 65K int limit, hence this hack of a method | |
$myBuildNumber = (Get-Date).Year + ((Get-Date).Month * 31) + (Get-Date).Day | |
$myBuildNumber = $majorNumber + "." + $minorNumber + "." + $myBuildNumber + "." + $revisionNumber | |
$xml = New-Object XML | |
$xml.Load($filePath) | |
$xml.Project.PropertyGroup.Version = $myBuildNumber | |
$xml.Save($filePath) | |
Write-Host "Updated csproj "$csprojPath" and set to version "$myBuildNumber | |
} | |
else { | |
Write-Host "ERROR: Something was wrong with the build number" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added params and support for multiple projects to update.