Created
January 7, 2019 10:23
-
-
Save Misiu/1196634407d532275dd4442512136a14 to your computer and use it in GitHub Desktop.
Nuspec & Nupkg versioning
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
Param( | |
[Parameter(mandatory=$true)] | |
[string]$packagesDirectory | |
) | |
$compressDirectory = | |
{ | |
param($directoryPath, $destinationPath) | |
Compress-Archive -path "$directoryPath\*" -DestinationPath $destinationPath -Force | |
} | |
Write-Output "Searching for .nuspec files in $packagesDirectory" | |
$files = gci "$packagesDirectory" -recurse | ?{ $_.Extension -eq ".nuspec" } | foreach { gci -Path $_.FullName -Recurse -include *.nuspec } | |
if($files) | |
{ | |
foreach ($nuspecFile in $files) | |
{ | |
$zipDestinationPath = Join-Path -Path $nuspecFile.Directory.Parent.FullName -ChildPath "$($nuspecFile.Directory.Name).zip" | |
Write-Output "Starting compression of $($nuspecFile.Directory.FullName)" | |
$job = Start-Job -ScriptBlock $compressDirectory -ArgumentList $nuspecFile.Directory.FullName, $zipDestinationPath | Wait-Job | |
if($job.State -ne "Completed") | |
{ | |
$errorReason = $job.ChildJobs[0].JobStateInfo.Reason.Message | |
Write-Error "There was an issue compressing the directory at $ because: $errorReason" | |
} | |
else | |
{ | |
Write-Output "Successfully compressed the directory to $zipDestinationPath" | |
} | |
# Rename the nuget package from a .nupkg to .zip extension and extract the archive | |
$newName = $zipDestinationPath -replace ".zip", ".nupkg" | |
Write-Output "Renaming $zipDestinationPath to $newName" | |
Rename-Item -Path $zipDestinationPath -NewName $newName | |
Write-Output "Deleting directory: $($nuspecFile.Directory.FullName)" | |
Remove-Item $nuspecFile.Directory -Recurse | |
} | |
} | |
else | |
{ | |
Write-Warning "Found no *.nuspec files." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment