Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomartinspro/8a7ae713ab6b5191fa2f4fb284ed8673 to your computer and use it in GitHub Desktop.
Save brunomartinspro/8a7ae713ab6b5191fa2f4fb284ed8673 to your computer and use it in GitHub Desktop.
Modify .Net Core Nuget Package Version using Powershell
$filePath = "$(Build.SourcesDirectory)"
$projectNameFilter = "MYBASEPROJECTNAME.*"
Write-Output ("package version: $(NugetVersion)")
Get-ChildItem "$filePath" -Filter "$projectNameFilter.csproj" -recurse | Foreach-Object {
Write-Output ("----------------- CSPROJ FILTER: " + $_.FullName + "----------------------")
try {
$regex = '(?<=<Version>)[^<]*'
(Get-Content $_.FullName) -replace $regex, "$(NugetVersion)" | Set-Content $_.FullName
$regex = '(?<=<PackageReference Include="$projectNameFilter" Version=")[^"]*'
(Get-Content $_.FullName) -replace $regex, "$(NugetVersion)" | Set-Content $_.FullName
Write-Output (Get-Content $_.FullName)
}
catch {
Write-Output ("Error: $_")
}
Write-Output ("----------------- CSPROJ FILTER: " + $_.FullName + "----------------------")
}
Get-ChildItem "$filePath" -Filter "$projectNameFilter.nuspec" -recurse | Foreach-Object {
Write-Output ("----------------- NUSPEC FILTER: " + $_.FullName + "----------------------")
try {
$regex = '(?<=<id>)($projectNameFilter)[^<]*'
$content = (Get-Content $_.FullName)
$match = [regex]::match("$content",$regex).Groups[0].Value
if(![string]::IsNullOrEmpty("$match"))
{
$regex = '(?<=<version>)[^<]*'
(Get-Content $_.FullName) -replace $regex, "$(NugetVersion)" | Set-Content $_.FullName
}
$regex = '(?<=<dependency id="$projectNameFilter" version=")[^"]*'
(Get-Content $_.FullName) -replace $regex, "$(NugetVersion)" | Set-Content $_.FullName
Write-Output (Get-Content $_.FullName)
}
catch {
Write-Output ("Error: $_")
}
Write-Output ("----------------- NUSPEC FILTER: " + $_.FullName + "----------------------")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment