144

Firstly, I do not want to use Visual Studio at all when dealing with the certain .nupkg files.

I know there is a tool called NuGet Package Explorer and this can export nupkg files to a certain file location using a gui, but I'm looking to setup a MSBuild task to run and unpack about 50 .nupkg files, using the command line.

My question is, is there a tool you can use via the command line which will unpack .nupkg files to a specified file location?

7 Answers 7

192

NuPKG files are just zip files, so anything that can process a zip file should be able to process a nupkg file, i.e, 7zip.

Sign up to request clarification or add additional context in comments.

3 Comments

There is a proviso with this, which is that NuGet seems to do some sort of encoding of filenames. So, if you use a zip tool, a file you orginally named "A+B.txt" for example will be extracted as "A%2B.txt". This is avoided by using nuget install (as per Andy's answer)
the file encoding issue was fixed in 4.7.0+
github.com/NuGet/Home/issues/9459 Links to some side effects of not encoding the filenames, but also links in the comments to the original issues where it was changed, for reference. Note: The are compatibility issues with Nuget 2.x
131

You can also use the NuGet command line, by specifying a local host as part of an install. For example if your package is stored in the current directory

nuget install MyPackage -Source %cd% -OutputDirectory packages

will unpack it into the target directory.

7 Comments

Just a note that MyPackage is actually a Package ID that is specified in the .nuspec file and not a file name.
and you have to execute it from console with admin privileges
Fwiw, in powershell the command looks like: nuget install MyPackage -Source $pwd -OutputDirectory packages
I used the absolute path to the file directory to get the -Source to work for me. I didn't include the package name.
I had trouble installing my package because the .nupkg file name did not line up with what was specified in the .nuspec. After renaming the .nupkg to include the version i was able to install it locally: NuGet.exe install <packageName> -PreRelease -Source "Directory\To\.nupkg" -Version <full version> -NoCache -DirectDownload -OutputDirectory D:\temp, where the .nupkg physical file name was <Nuget Id>.<Version>.nupkg
|
48

Rename it to .zip, then extract it.

1 Comment

This is an extremely old question, and if you just change it to a zip that will not answer the question, if you use a zip tool, a file you originally named "A+B.txt" for example will be extracted as "A%2B.txt" - You also don't need to rename it to zip.
6

did the same thing like this:

clear
cd PACKAGE_DIRECTORY

function Expand-ZIPFile($file, $destination)
{
    $shell = New-Object -ComObject Shell.Application
    $zip = $shell.NameSpace($file)
    foreach($item in $zip.items())
    {
        $shell.Namespace($destination).copyhere($item)
    }
}

Dir *.nupkg | rename-item -newname {  $_.name  -replace ".nupkg",".zip"  }

Expand-ZIPFile "Package.1.0.0.zip" “DESTINATION_PATH”

1 Comment

Dosent this suffer from the same problem as Oli Wennell mention above? i.e. "A+B.txt" for example will be extracted as "A%2B.txt"?
5

Just do unzip package-name.nupkg -d OutputDir

1 Comment

This worked great on macOS, thank you. Trying to open it raw with the built-in "Archive Utility.app" causes it to compress it to a .cpgz file, and renaming to .zip and doing the same causes an error: Unable to expand "{package.zip}". It is in an unsupported format.
4

With PowerShell 5.1 (PackageManagement module)

Install-Package -Name MyPackage -Source (Get-Location).Path -Destination C:\outputdirectory

Comments

1

This worked for me:

Rename-Item -Path A_Package.nupkg -NewName A_Package.zip

Expand-Archive -Path A_Package.zip -DestinationPath C:\Reference

3 Comments

At least in PS 7.1.2 you can can use Expand-Archive without changing the file extension on MacOS.
@Phatmandrake +1 you are correct and this should be an answer, I just verified myself on Big Sur + PS 7.1.3
This break folder names e.g. Test Folder will be extracted as Test%20Folder. There will also be extra files in the extracted folder e.g _rels

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.