Instantly share code, notes, and snippets.

Embed
What would you like to do?
the detail of the PatchAssemblyInfo task
Task PatchAssemblyInfo{
function GetAssemblyVersion {
#skip the details for now -> returns the version major.minor (e.g. "6.7")
}
function GetAssemblyFileVersion {
#skip the details for now -> returns the long version major.minor.build (e.g. "6.7.35698")
}
function PatchFile ([string] $pattern, [string] $replaceString, [string] $fullPath){
#skip the details for now -> patch the file at $fullPath replace lines matching $pattern with $replaceString.
}
$assemblyVersion = GetAssemblyVersion
$assemblyFileVersion = GetAssemblyFileVersion
$targetDir = Split-Path (Join-Path $PSScriptRoot -ChildPath "..\..\..") -Parent #root path of the repository
Get-ChildItem $targetDir -Recurse |
Where-Object{ $_.Name -eq "AssemblyInfo.cs" } | #retrieves all AssemblyInfo.cs files
Foreach-Object {
Write-Host "Patching file " $_.FullName #logs the file processed
$assemblyVersionPattern = 'AssemblyVersion\("(\d+).(\d+).(\*|\d+\.\d+|\d+\.\*)"\)'
$assembyVersionReplacement ='AssemblyVersion("' + $revision + '")'
PatchFile $assemblyVersionPattern $assembyVersionReplacement $_.FullName
$assemblyFileVersionPattern = 'AssemblyFileVersion\("(\d+).(\d+).(\*|\d+\.\d+|\d+\.\*)"\)'
$assembyFileVersionReplacement ='AssemblyFileVersion("' + $revision + '")'
PatchFile $assemblyFileVersionPattern $assembyFileVersionReplacement $_.FullName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment