pf-AseemblyVersion.ps1
function Update-AssemblyInfo { param ( [Parameter(ValueFromPipeline=$true)] $filename, [string]$buildSequence ) begin { $versionReplace = '${v1}.${v2}.${v3}.' + $buildSequence $VersionFmt = '(?<v1>\d+)\.(?<v2>\d+)\.(?<v3>\d+)\.(?<v4>(\w+|\*))' } Process { [string]$filename = $filename | Get-Path write-Debug $filename $gitInfo = Get-Git_HeadHash $filename | Update-FileContent_Replace -find '[assembly: AssemblyInformationalVersion("*")]' -replacement "[assembly: AssemblyInformationalVersion(`"$gitInfo`")]" $content = [System.IO.File]::ReadAllText($filename); #$content = Set-CSharp_Attribute $content "AssemblyVersion" $VersionFmt $versionReplace #$version = Get-CSharp_Attribute $content "AssemblyVersion" $VersionFmt # #$newVersion = New-Object System.Version $version $content = Set-CSharp_Attribute $content "AssemblyFileVersion" $VersionFmt $versionReplace [System.IO.File]::WriteAllText($filename, $content); #Update-File_Replace_PSTemplate -file $filename } } function Update-AssemblyInfo:::Example { #$baseVersion = Get-TFS_BaseBuildVersion Import-Module .\PSModules\Common Import-Module GIT.Utils $buildSequence = Get-GitCommitCount $assemblyInfoList = Get-ChildItem -Path $src -fi AssemblyInfo.cs -Recurse | Sort-Object lastwritetime -Descending | Select-Object -First 1 $assemblyInfoList | Update-AssemblyInfo -buildSequence $buildSequence } function Set-CSharp_Attribute ([string[]]$content, [string]$attribute, [string]$toReplace, [string]$replacement) { return $content -replace ( Get-CSharp_Attribute_RegEx $attribute $toReplace ), $replacement } function Get-CSharp_Attribute ([string]$content, [string]$attribute, [string]$toFind) { return $content | select-string -Pattern ( Get-CSharp_Attribute_RegEx $attribute $toFind) | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } } function Get-CSharp_Attribute_RegEx ([string]$attribute, [string]$match) { return "(?<=\[.*?$attribute.*?)$match(?=.*?])" } |