Nuget copy and add files to solution level

帅比萌擦擦* 提交于 2021-02-07 06:47:28

问题


I want to create a NUGET package that adds several files to a certain solution folder. Specifically, the package must, on installation, do the following:

  1. Create a temp folder in the target project.
  2. Copy all the files matching an extension (say *.txt) to the temp folder.
  3. Move the files to Solution root.
  4. Create a Solution folder named "Solution Items".
  5. Add all the files just moved to that solution folder.
  6. Remove the temp folder from both solution and disk.

I use the package.nuspec file to create a temp directory and dump the files and init.ps1 to do the rest.

Unfortunately nothing happens beyond step 1.


This is my package.nuspec file.

<?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>

This is my init.ps1 file.

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
}

回答1:


when you open the package that you've created using the nuspec in nuget package explorer, did you see any .txt files in the content\temp folder?

when nuget.exe pack is called, it will copy the .txt files from the source\ folder to content\temp while making the package itself.

for more information, please refer to http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package



来源:https://stackoverflow.com/questions/20759795/nuget-copy-and-add-files-to-solution-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!