Skip to content

Commit 109977f

Browse files
committed
Create update_version.ps1
1 parent ace77ae commit 109977f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

update_version.ps1

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
###################
2+
## PS script to implement a semantic versioning change from (say) 8.0.x to 8.1
3+
## across all interdependent cs packages
4+
5+
## Wherever we have <Version>8.0.n</Version> replace it to <Version>8.1.0</Version> where n >= 0
6+
7+
## Wherever we have <PackageReference Include="cloudscribe.Anything" Version="8.0.*" /> replace it to <PackageReference Include="cloudscribe.Anything" Version="8.1.*" />
8+
9+
## Wherever we have <PackageReference Include="cloudscribe.Anything" Version="8.0.n" /> replace it to <PackageReference Include="cloudscribe.Anything" Version="8.1.0" /> where n >= 0
10+
11+
## Exclude cloudscribe.HtmlAgilityPack and DbHelpers because those ones are ancient and frozen
12+
###################
13+
14+
15+
# Define the directory containing the .csproj files
16+
$directory = "src"
17+
18+
# Define the old & new versions
19+
$oldVersion = '8\.1' # slash needed !
20+
$newVersion = "8.2.0"
21+
$newWildcardVersion = "8.2.*"
22+
23+
24+
# Get all .csproj files in the directory and subdirectories
25+
$csprojFiles = Get-ChildItem -Path $directory -Recurse -Filter *.csproj
26+
27+
foreach ($file in $csprojFiles) {
28+
# Read the content of the .csproj file
29+
$content = Get-Content -Path $file.FullName
30+
31+
# Update the version of cloudscribe package references, except for cloudscribe.HtmlAgilityPack and cloudscribe.DbHelpers
32+
33+
$wildCardPattern = '(?<=<PackageReference Include="cloudscribe\.(?!HtmlAgilityPack|DbHelpers)[^"]+" Version=")' + $oldVersion + '\.\*'
34+
$updatedContent = $content -replace $wildCardPattern, $newWildcardVersion
35+
36+
$digitPattern = '(?<=<PackageReference Include="cloudscribe\.(?!HtmlAgilityPack|DbHelpers)[^"]+" Version=")' + $oldVersion + '\.\d+'
37+
$updatedContent = $updatedContent -replace $digitPattern, $newVersion
38+
39+
# Update the <Version> element if it matches the pattern
40+
$versionPattern = '<Version>' + $oldVersion + '\.\d+</Version>'
41+
$replacement = "<Version>$newVersion</Version>"
42+
$updatedContent = $updatedContent -replace $versionPattern, $replacement
43+
44+
45+
# Write the updated content back to the .csproj file
46+
Set-Content -Path $file.FullName -Value $updatedContent
47+
48+
Write-Host "Updated $file.FullName"
49+
}
50+
51+
Write-Host "All cloudscribe package references (except cloudscribe.HtmlAgilityPack and cloudscribe.DbHelpers) and <Version> elements have been updated to version $newVersion or $newWildcardVersion as appropriate."
52+

0 commit comments

Comments
 (0)