forked from dobrou/CsvLINQPadDriver
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Update-Version.ps1
64 lines (46 loc) · 1.98 KB
/
Update-Version.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
56
57
58
59
60
61
62
63
64
<#
.SYNOPSIS
Gets project version from Directory.Build.props and updates it for dependent files.
.DESCRIPTION
Gets project version from Directory.Build.props and updates it for dependent files. Prints version and release notes.
.EXAMPLE
pwsh ./Update-Version.ps1
Gets project version from Directory.Build.props and updates it for dependent files.
#>
[CmdletBinding()]
param()
#requires -Version 7
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$Verbose = $VerbosePreference -ne 'SilentlyContinue'
$PSDefaultParameterValues['*:Verbose'] = $Verbose
$PSDefaultParameterValues['*:ErrorAction'] = $ErrorActionPreference
$ThisFolder = Split-Path (Get-Item (&{ $MyInvocation.ScriptName }))
function Main
{
$projectFolder = Join-Path $ThisFolder Src\CsvLINQPadDriver
$buildPropsFile = Join-Path $projectFolder Directory.Build.props
$appManifestFile = Join-Path $projectFolder app.manifest
$lpxBuildScriptFile = Join-Path $ThisFolder Deploy\buildlpx.cmd
Write-Output "Reading '$buildPropsFile'..."
$buildPropsXml = ([xml](Get-Content $buildPropsFile)).Project.PropertyGroup[0]
$version = $buildPropsXml.Version
$buildProps = [PSCustomObject]@{
Version = $version
FullVersion = "$version.0"
ReleaseNotes = $buildPropsXml.PackageReleaseNotes
}
$fieldsFormat =
@{ n = 'Version'; e = { $_.Version } },
@{ n = 'Full version'; e = { $_.FullVersion } },
@{ n = 'Release notes'; e = { $_.ReleaseNotes } }
Write-Output "`n$(($buildProps | Format-List $fieldsFormat | Out-String).Trim())`n"
Update-Content $appManifestFile '(?<=CsvLINQPadDriver[\s\S]+\s+version=")[^"]+(?=[\s\S]+?type)',$buildProps.FullVersion
Update-Content $lpxBuildScriptFile '(?<=version=)[^\r\n]+',$buildProps.Version
}
function Update-Content($file, $replace)
{
Write-Output "Updating '$file'..."
(Get-Content $file -Raw) -replace $replace | Set-Content $file -NoNewline
}
. Main