Skip to content

Instantly share code, notes, and snippets.

@jokecamp
Created March 18, 2017 17:34
Show Gist options
  • Save jokecamp/a2a314d62490fca1517a9a031c5606e9 to your computer and use it in GitHub Desktop.
Save jokecamp/a2a314d62490fca1517a9a031c5606e9 to your computer and use it in GitHub Desktop.
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