Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NuGet.exe to install/update content-only package without a project file

We have a local NuGet feed that includes some JS content-only packages.
I want to install those packages in a plain JS app (that I edit in Brackets and where I don't use VS at all). Obviously something like Bower would be more appropriate, but I don't want to maintain two package feed systems.

If I do nuget install MyPackage, it downloads and unpacks the packages, but does not copy content files to subfolders (in fact it downloads the packages in the current folder).

Can I use nuget.exe to actually copy the content, or does it have to be an external step?

like image 949
Andrey Shchekin Avatar asked Nov 24 '25 06:11

Andrey Shchekin


1 Answers

OK, here is some initial work I did for command-line update (which would work for install just as well, if you modify packages.config manually).

It has the following limitations:

  1. It expects that you keep your packages in nuget_packages folder (similar to node_modules).
  2. You need to have a packages.config file in that folder.
  3. Only contents of the content folder are copied, no installs are run etc.
  4. If you have an existing file/folder with the same name as content file/folder, it will be overwritten.

Code:

Set-StrictMode -Version 2
$ErrorActionPreference = 'Stop'

$packagesDirectory = (Get-Item nuget_packages)

$packagesDirectory.GetDirectories() | % {
    Write-Host "Deleting $_"
    Remove-Item $_.FullName -Recurse
}
Write-Host "Starting nuget.exe"
Start-Process nuget -ArgumentList "install packages.config" -WorkingDirectory nuget_packages -NoNewWindow -Wait

$packagesDirectory.GetDirectories() | % {
    $contentPath = Join-Path (Join-Path $packagesDirectory.Name $_) 'content'
    if (!(Test-Path $contentPath)) {
        return;
    }

    Get-ChildItem $contentPath -Exclude *.transform | % {
        $target = $_.Name
        if (Test-Path $target) {
            Write-Host "Deleting $target"
            Remove-Item $target -Recurse
        }

        Write-Host "Copying $(Join-Path $contentPath $_.Name) to $target"
        Copy-Item $_.FullName -Destination $target -Recurse
    }
}
like image 177
Andrey Shchekin Avatar answered Nov 28 '25 16:11

Andrey Shchekin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!