-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateProjectVersion.ps1
More file actions
66 lines (51 loc) · 1.99 KB
/
UpdateProjectVersion.ps1
File metadata and controls
66 lines (51 loc) · 1.99 KB
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
65
66
param (
[Parameter(Mandatory = $true)]
[string]$NewVersion
)
# Function to update the version in a project file
function Update-VersionInFile {
param (
[string]$FilePath,
[string]$Version
)
Write-Host "Updating version in project file: $FilePath" -ForegroundColor Green
# Load the file content
$content = Get-Content -Path $FilePath
# Update the <Version> tag
$updatedContent = $content -replace '<Version>.*?</Version>', "<Version>$Version</Version>"
# Save the updated content back to the file
Set-Content -Path $FilePath -Value $updatedContent
}
# Function to update the version in the Package.wxs file
function Update-VersionInPackageWxs {
param (
[string]$FilePath,
[string]$Version
)
Write-Host "Updating version in Package.wxs file: $FilePath" -ForegroundColor Green
# Auto-expand version to X.Y.0 if it's in the format X.Y
if ($Version -match '^\d+\.\d+$') {
$Version = "$Version.0"
}
# Load the file content
$content = Get-Content -Path $FilePath
# Update the Version attribute in the Package node
$updatedContent = $content -replace '(?<=<Package[^>]*\sVersion=")[^"]*', "$Version"
# Save the updated content back to the file
Set-Content -Path $FilePath -Value $updatedContent
}
# Get all .csproj files in the current directory and subdirectories
$csprojFiles = Get-ChildItem -Path . -Recurse -Include *.csproj
# Update version in all .csproj files
foreach ($file in $csprojFiles) {
Update-VersionInFile -FilePath $file.FullName -Version $NewVersion
}
# Find the Package.wxs file
$packageWxsFile = Get-ChildItem -Path . -Recurse -Include Package.wxs
# Update version in the Package.wxs file if it exists
if ($packageWxsFile) {
Update-VersionInPackageWxs -FilePath $packageWxsFile.FullName -Version $NewVersion
} else {
Write-Host "Package.wxs file not found." -ForegroundColor Yellow
}
Write-Host "Version update completed for all project files." -ForegroundColor Cyan