Skip to content

Instantly share code, notes, and snippets.

@Misiu
Created January 7, 2019 10:23
Show Gist options
  • Save Misiu/f8483f2d02fe392f1d14eef96b1afb1e to your computer and use it in GitHub Desktop.
Save Misiu/f8483f2d02fe392f1d14eef96b1afb1e to your computer and use it in GitHub Desktop.
Nuspec & Nupkg versioning
Param(
[Parameter(mandatory=$true)]
[string]$packagesDirectory
)
$expandZipFile =
{
param($zipFile, $zipDestinationPath)
Expand-Archive -path "$zipFile" -DestinationPath $zipDestinationPath -Force
}
Write-Output "Searching for .nupkg files in $packagesDirectory"
$files = gci "$packagesDirectory" -recurse | ?{ $_.Extension -eq ".nupkg" } | foreach { gci -Path $_.FullName -Recurse -include *.nupkg }
if($files)
{
foreach ($nugetPackageFile in $files)
{
$zipFilename = $nugetPackageFile.Name -replace ".nupkg", ".zip"
$packageName = [io.path]::GetFileNameWithoutExtension($nugetPackageFile)
$zipDestinationDirectory = Join-Path -Path $nugetPackageFile.Directory -ChildPath $packageName
$zipFilepath = Join-Path -Path $nugetPackageFile.Directory -ChildPath $zipFilename
# Rename the nuget package from a .nupkg to .zip extension and extract the archive
Write-Output "Renaming $($nugetPackageFile.Name) to $zipFilename"
Rename-Item -Path $nugetPackageFile.FullName -NewName $zipFilename
if(!$(Test-Path $packagesDirectory)) { Write-Error "Could not find the packages directory at $packagesDirectory" }
if(!$(Test-Path $zipFilepath)) { Write-Error "Could not find a zip file at $zipFilepath" }
$zipFile = Get-ChildItem $zipFilepath
Write-Output "Starting extraction of $zipFile"
$job = Start-Job -ScriptBlock $expandZipFile -ArgumentList $zipFile, $zipDestinationDirectory | Wait-Job
if($job.State -ne "Completed")
{
$errorReason = $job.ChildJobs[0].JobStateInfo.Reason.Message
Write-Error "There was an issues unzipping the file at $zipFile because: $errorReason"
}
else
{
Write-Output "Successfully extracted the zip file to $zipDestinationDirectory"
}
}
}
else
{
Write-Warning "Found no *.nupkg files."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment