简体   繁体   English

使用NuGet.exe安装/更新没有项目文件的仅内容包

[英]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. 我们有一个本地NuGet提要,其中包含一些仅限JS内容的包。
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). 我想在一个普通的JS应用程序中安装这些软件包(我在Brackets中编辑,我根本不使用VS)。 Obviously something like Bower would be more appropriate, but I don't want to maintain two package feed systems. 显然像Bower这样的东西会更合适,但我不想维护两个包裹饲料系统。

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). 如果我确实nuget install MyPackage ,它会下载并解压缩包,但不会将内容文件复制到子文件夹(实际上它会下载当前文件夹中的包)。

Can I use nuget.exe to actually copy the content, or does it have to be an external step? 我可以使用nuget.exe实际复制内容,还是必须是外部步骤?

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). 好的,这是我为命令行更新做的一些初步工作(如果你手动修改packages.config,它也适用于安装)。

It has the following limitations: 它有以下限制:

  1. It expects that you keep your packages in nuget_packages folder (similar to node_modules). 它希望您将包保存在nuget_packages文件夹中(类似于node_modules)。
  2. You need to have a packages.config file in that folder. 您需要在该文件夹中有一个packages.config文件。
  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
    }
}

I used the tag <contentFiles> with flatten="true" to download package files at the root. 我使用标签<contentFiles> with flatten =“true”在根目录下载包文件。 My nuget package contains Typescript files. 我的nuget包中包含Typescript文件。

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

I was initially using the <files> tag, this extracts the files at the location root/package.name/content/{files} 我最初使用的是<files>标签,这会在位置root / package.name / content / {files}中提取文件

This might help someone 这可能对某人有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决NuGet.exe命令行无法安装xunit 2.1.0的问题? - How can I resolve NuGet.exe command line being unable to install xunit 2.1.0? 从命令行获取 NuGet.exe 版本 - Get NuGet.exe version from command-line 如何从命令行更新项目中的单个nuget包? - How do I update a single nuget package in a project from the command line? 使用命令行检查nuget包是否存在 - Check if nuget package exists using command line NuGet:通过PowerShell或CMD将软件包更新到所有项目中的特定版本 - NuGet: Update a package to a specific version in all projects via PowerShell or CMD BASH:仅在文件中的定界符之间搜索,而无需使用“剪切” - BASH: Search only between delimiters in file without using “cut” 如何使用 Azure DevOps 安装 windows 桌面应用程序 (.exe)? - how to install windows desktop application (.exe) using Azure DevOps? Windows服务更新exe选项,无需删除/重新安装 - windows service update exe options without remove / reinstall 有没有一种方法可以在命令行上使用devenv.exe来仅链接项目而不是完全构建项目? - Is there a way to use devenv.exe on the command line to link-only a project instead of full-build a project? 如何在没有 .exe 文件的情况下从 C# 运行 python - How to run python from C# without .exe file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM