-
Notifications
You must be signed in to change notification settings - Fork 13
/
patch_csproj.ps1
executable file
·57 lines (51 loc) · 1.69 KB
/
patch_csproj.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
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
.SYNOPSIS
.
.DESCRIPTION
.
.PARAMETER Patch
Patch matching project files
.PARAMETER File
The pattern for patching project files
.PARAMETER Version
The value to set as new version
.PARAMETER PackageVersion
The value to set as new package version
.PARAMETER AssemblyVersion
The value to set as new assembly version
.PARAMETER FileVersion
The value to set as new file version
.PARAMETER InformationalVersion
The value to set as new informational version
#>
param (
[Parameter(Mandatory=$false)][switch]$Patch = $false,
[Parameter(Mandatory=$false)][string]$Version,
[Parameter(Mandatory=$false)][string]$PackageVersion,
[Parameter(Mandatory=$false)][string]$AssemblyVersion,
[Parameter(Mandatory=$false)][string]$FileVersion,
[Parameter(Mandatory=$false)][string]$InformationalVersion,
[string]$File = '**\*.csproj'
)
$files = Get-Childitem "$PSScriptRoot\$File" -Recurse
$versionNodes = "Version", "PackageVersion", "AssemblyVersion", "FileVersion", "InformationalVersion"
foreach($patchFile in $files) {
$xml = [xml](Get-Content $patchFile)
$fileModified = $false;
foreach ($versionNode in $versionNodes) {
$paramValue = Get-Variable -ValueOnly $versionNode;
if (![string]::IsNullOrWhitespace($paramValue)) {
$elements = $xml.SelectNodes("//$versionNode")
foreach ($element in $elements) {
Write-Output "$patchFile[$versionNode]: $paramValue"
if ($Patch) {
$element.InnerText = $paramValue
$fileModified = $true;
}
}
}
}
if ($Patch -and $fileModified) {
$xml.Save($patchFile)
}
}