134

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?

Lewis
  • 2,373
  • 2
  • 22
  • 30

6 Answers6

182

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.

Calvin Allen
  • 4,176
  • 4
  • 31
  • 31
  • 17
    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) – Oli Wennell Jul 30 '15 at 12:56
  • 5
    the file encoding issue was fixed in 4.7.0+ – Fai Aug 07 '18 at 18:50
  • https://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 – TheCodingHatter Mar 11 '21 at 19:33
125

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.

Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
Andy
  • 3,596
  • 8
  • 34
  • 33
  • 21
    Just a note that MyPackage is actually a Package ID that is specified in the .nuspec file and not a file name. – Rod Oct 06 '16 at 00:23
  • and you have to execute it from console with admin privileges – Sonic Soul Sep 18 '17 at 22:53
  • 8
    Fwiw, in powershell the command looks like: nuget install MyPackage -Source $pwd -OutputDirectory packages – Mark Boltuc Mar 29 '18 at 16:47
  • I guess %cd% is referring to the current directory. How can I refer to different path in my local system? it does not work when I use a path. "./example/path/" – seanbun Jun 04 '18 at 00:54
  • 4
    I used the absolute path to the file directory to get the -Source to work for me. I didn't include the package name. – mac10688 Oct 23 '18 at 20:14
  • @Rod I am using docker file and need the utilize my .nupkg file and running the below command but linux container doesn't find Install command . What should I do? RUN Install-Package BuildingBlock.Messaging.Publisher -Source "." "ProductService.Catalog/" – Manish Kumar May 20 '21 at 12:42
  • 1
    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 -PreRelease -Source "Directory\To\.nupkg" -Version -NoCache -DirectDownload -OutputDirectory D:\temp, where the .nupkg physical file name was ..nupkg – Warren May 21 '21 at 19:10
35

Rename it to .zip, then extract it.

Shadi Alnamrouti
  • 11,796
  • 4
  • 56
  • 54
  • 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. – Lewis Jun 12 '19 at 23:11
5

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”
UsmanShabbir
  • 101
  • 1
  • 4
  • 2
    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"? – Rahatur Apr 07 '16 at 20:26
3

With PowerShell 5.1 (PackageManagement module)

Install-Package -Name MyPackage -Source (Get-Location).Path -Destination C:\outputdirectory
Mariusz
  • 346
  • 3
  • 6
1

This worked for me:

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

Expand-Archive -Path A_Package.zip -DestinationPath C:\Reference
Lumito
  • 490
  • 6
  • 20
christiandersen
  • 193
  • 1
  • 5
  • 3
    At least in PS 7.1.2 you can can use Expand-Archive without changing the file extension on MacOS. – Phatmandrake Mar 14 '21 at 22:57
  • @Phatmandrake +1 you are correct and this should be an answer, I just verified myself on Big Sur + PS 7.1.3 – Wes Jun 20 '21 at 15:18
  • 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 – Mariusz Feb 20 '23 at 22:13