Skip to content

Instantly share code, notes, and snippets.

@Misiu
Created January 7, 2019 10:23
Show Gist options
  • Save Misiu/1196634407d532275dd4442512136a14 to your computer and use it in GitHub Desktop.
Save Misiu/1196634407d532275dd4442512136a14 to your computer and use it in GitHub Desktop.
Nuspec & Nupkg versioning
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