forked from NLog/NLog.Extensions.Logging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchFileVersion.ps1
42 lines (28 loc) · 929 Bytes
/
patchFileVersion.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
param([string]$filewildCard, [string]$version)
#returns FileInfo
function findFile([string]$filewildCard) {
$files = @(Get-ChildItem $filewildCard -Recurse);
if ($files.Length -gt 1) {
throw "Found $($files.length) files. Stop, we need an unique pattern"
}
if ($files.Length -eq 0) {
throw "Find not found with pattern $filewildCard. Stop"
}
return $files[0];
}
function patchAssemblyFileVersion([System.IO.FileInfo]$file , [string]$version) {
$xmlPath = $file.FullName;
$xml = [xml](get-content $xmlPath)
$propertyGroup = $xml.Project.PropertyGroup
Write-Host "patch $xmlPath to $version"
# FileVersion = AssemblyFileVersionAttribute
$propertyGroup[0].FileVersion = $version
$xml.Save($xmlPath)
}
$file = findFile $filewildCard -ErrorAction Stop
patchAssemblyFileVersion $file $version -ErrorAction Stop
trap
{
write-output $_
exit 1
}