Instantly share code, notes, and snippets.

Embed
What would you like to do?
function getVersion()
{
$tag = iex "git describe --long --tags --always"
$a = [regex]"v\d+\.\d+\.\d+\-\d+"
$b = $a.Match($tag)
$b = $b.Captures[0].value
$b = $b -replace '-', '.'
$b = $b -replace 'v', ''
Write-Host "Version found: $b"
return $b
}
function SetVersion ($file, $version)
{
"Changing version in $file to $version"
$fileObject = get-item $file
#$fileObject.Set_IsReadOnly($False)
$sr = new-object System.IO.StreamReader( $file, [System.Text.Encoding]::GetEncoding("utf-8") )
$content = $sr.ReadToEnd()
$sr.Close()
$content = [Regex]::Replace($content, "(\d+)\.(\d+)\.(\d+)[\.(\d+)]*", $version);
$sw = new-object System.IO.StreamWriter( $file, $false, [System.Text.Encoding]::GetEncoding("utf-8") )
$sw.Write( $content )
$sw.Close()
#$fileObject.Set_IsReadOnly($True)
}
function setVersionInDir($dir, $version) {
if ($version -eq "") {
Write-Host "version not found"
exit 1
}
# Set the Assembly version
$info_files = Get-ChildItem $dir -Recurse -Include "AssemblyInfo.cs" | where {$_ -match 'npr.nf'}
foreach($file in $info_files)
{
Setversion $file $version
}
}
# First get tag from Git
$version = getVersion
$dir = "./"
setVersionInDir $dir $version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment