7

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
}
Kiquenet
  • 14,494
  • 35
  • 148
  • 243

1 Answers1

-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

Dan Liu
  • 812
  • 5
  • 1
  • I do see the files, alright, but that does not help my problem. I know where the files are going by default. I want to force the files to be added at the **solution** level, _not_ at the **project** level. – Chameera Dedduwage Mar 11 '14 at 08:19
  • `-1 ` I thought the title of the question was rather self-explanatory. – Kenneth K. Jun 13 '14 at 15:38