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

We have a local NuGet feed that includes some JS-only content packs.
I want to install these packages in a simple JS application (which 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 support two packet delivery systems.

If I execute nuget install MyPackage

, it downloads and unpacks the packages, but does not copy the 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 should it be an external step?

+3


source to share


2 answers


OK, here is some initial work I did to update the command line (which will also work for installation if you modify the packages.config file manually).

It has the following limitations:

  • It expects you to save your packages in the nuget_packages folder (similar to node_modules).
  • There should be a package.config file in this folder.
  • Copied only the contents of the content folder, no installations start, etc.
  • If you have an existing file / folder with the same name as the 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
    }
}

      

+1


source


I used a tag <contentFiles>

with flatten = "true" to download the package files to the root directory. My nuget package contains Typescript files.

 <contentFiles>
        <files include="cm-common/**/*" buildAction="None" flatten="true" />
</contentFiles>

      



At first I used a tag <files>

that extracts files at the root / package.name / content / {files} location

This might help someone

0


source







All Articles