Nuget复制并将文件添加到解决方案级别

Cha*_*age 6 powershell init nuget nuget-package

我想创建一个NUGET包,将几个文件添加到某个解决方案文件夹中.具体而言,在安装时,包必须执行以下操作:

  1. 在目标项目中创建临时文件夹.
  2. 将与扩展名匹配的所有文件(例如*.txt)复制到临时文件夹.
  3. 将文件移动到Solution root.
  4. 创建名为"解决方案项"的解决方案文件夹.
  5. 添加刚刚移动到该解决方案文件夹的所有文件.
  6. 取下临时文件夹解决方案和磁盘.

我使用该package.nuspec文件创建临时目录并转储文件并init.ps1完成其余的工作.

不幸的是,在第1步之外没有任


这是我的package.nuspec档案.

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>IncludeFiles</id>
    <version>1.0</version>
    <authors>Chameera</authors>
    <owners>Chameera</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>dummy include files</description>
    <tags>dummy</tags>
  </metadata>
  <files>
    <file src="source\*.txt" target="content\temp" />
  </files>
</package>
Run Code Online (Sandbox Code Playgroud)

这是我的init.ps1档案.

param($installPath, $toolsPath, $package, $project)

$projectFullName = $project.FullName 
$fileInfo = new-object -typename System.IO.FileInfo -ArgumentList $projectFullName
$projectDirectory = $fileInfo.DirectoryName

$tempDirectory = "temp"
$sourceDirectory = "$projectDirectory\$tempDirectory"
$destinationDirectory = (get-item $sourceDirectory).parent.FullName

if(test-path $sourceDirectory -pathtype container)
{
 robocopy $sourceDirectory $destinationDirectory /XO

 $tempDirectoryProjectItem = $project.ProjectItems.Item($tempDirectory)
 $tempDirectoryProjectItem.Remove()

 remove-item $sourceDirectory -recurse
}
Run Code Online (Sandbox Code Playgroud)

小智 -1

当您在 nuget 包资源管理器中打开使用 nuspec 创建的包时,您是否在 content\temp 文件夹中看到任何 .txt 文件?

当调用 nuget.exe pack 时,它会将 .txt 文件从 source\ 文件夹复制到 content\temp,同时制作包本身。

有关更多信息,请参阅http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package