I had to replace the version xml file (NuGetApp1.nuspec) in a zipped nuget package, like so:
Original file content in zip:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>NuGetApp1</id>
<version>1.1.3-dev22222</version>
<title>NuGetApp1</title>
.....
Required :
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>NuGetApp1</id>
<version>1.0.0.0</version>
<title>NuGetApp1</title>
.....
Powershell Script:
$replaceWithVersion="1.0.0.0"
$path = "c:\temp\testnuget"
$files = Get-ChildItem *.nupkg -Path $path
foreach($fileNuget in $files)
{
$target = $fileNuget.FullName -replace "[0-9]+(\.([0-9]+|\*)){1,4}", $replaceWithVersion
Copy-Item $fileNuget.FullName -Destination $target
$zipfileName = $target
$fileToEdit = "*.nuspec"
# Open zip and find the particular file (assumes only one inside the Zip file)
$zip = [System.IO.Compression.ZipFile]::Open($zipfileName,"Update")
$nuspecFile = $zip.Entries.Where({$_.name -like $fileToEdit})
# Read the contents of the file
$desiredFile = [System.IO.StreamReader]($nuspecFile).Open()
$text = $desiredFile.ReadToEnd()
$desiredFile.Close()
$desiredFile.Dispose()
$text = $text -replace '<version>[\s\S]*?<\/version>',"<version>$replaceWithVersion</version>"
#update file with new content
$desiredFile = [System.IO.StreamWriter]($nuspecFile).Open()
$desiredFile.BaseStream.SetLength(0)
# Insert the $text to the file and close
$desiredFile.Write($text)
$desiredFile.Flush()
$desiredFile.Close()
# Write the changes and close the zip file
$zip.Dispose()
Write-Host "zip file updated"
}
Happy hunting:-)!