Nuget copy and add files to solution level

Viewed 2715

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 Answers
Related