On my current project we are struggling of updating multiple repositories after we are pushing a new version of our custom NuGet packages. A solution could be to use floating versions but I wanted more control over the versions, because there could be cases where I need different versions on each solutions. Therefore I went in the direction to update the versions manually on a developer machine. This way, pull requests needs to be opened for each package updates, but this is great because I want all developers aware of the changes.
The scripts below are made to automate this workflow. The following actions should run in order:
.\create-branches.ps1 -repos .\project-1,.\project-2 -branch feature/nuget-updates– this script checks out the master branch and creating and pushing a new branch with the given name.\upgrade-packages.ps1 -repos .\project-1,.\project-2– to run this snippet, first you need install dotnet-outdated-tool. This one jumps into each given repository directory and updating all package which starts withmy.custom.packages. After the update, it also runs a build to able detect build errors early..\push-branches.ps1 -repos .\project-1,.\project-2 -commit "Update packages"– the last one, it commits and pushes all changes in all given repositories.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## Be careful, because it's doing a git clean and git reset for all given repos! | |
| ## How to use: .\create-branches.ps1 -repos .\project-1,.\project-2 -branch feature/nuget-updates | |
| ## | |
| param ([string[]] $repos, [string] $branch) | |
| foreach ($repo in $repos) { | |
| Write-Host "[Create-Branches] Creating branch for" $repo -ForegroundColor "Green" | |
| Set-Location -Path $repo | |
| git checkout master | |
| git clean -fd | |
| git reset --hard | |
| git pull | |
| git checkout -B $branch | |
| git push -u origin $branch | |
| cd.. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## Prerequisite: dotnet tool install --global dotnet-outdated-tool | |
| ## How to use: .\upgrade-packages.ps1 -repos .\project-1,.\project-2 | |
| ## | |
| param ([string[]] $repos) | |
| foreach ($repo in $repos) { | |
| Write-Host "[Upgrade-Packages] Start to upgrade packages for" $repo -ForegroundColor "Green" | |
| Set-Location -Path $repo | |
| Write-Host "[Upgrade-Packages] Upgrade packages for" $repo -ForegroundColor "Green" | |
| dotnet outdated --include my.custom.packages -u | |
| Write-Host "[Upgrade-Packages] Build solution for" $repo -ForegroundColor "Green" | |
| dotnet build | |
| cd.. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| ## Be careful, because it's commiting and pushing to all given repos! | |
| ## How to use: .\push-branches.ps1 -repos .\project-1,.\project-2 -commit "Update packages" | |
| ## | |
| param ([string[]] $repos, [string] $commit) | |
| foreach ($repo in $repos) { | |
| Write-Host "[Push-Branches] Commit changes branch for" $repo -ForegroundColor "Green" | |
| Set-Location -Path $repo | |
| git add . | |
| git commit -m $commit | |
| git push | |
| cd.. | |
| } |
![Tamás Tárnok = [ C#, Sitecore, … ]](https://trnktms.com/wp-content/uploads/2021/11/pxart_white-small.png)