问题
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:
- Create a temp folder in the target project.
- Copy all the files matching an extension (say *.txt) to the temp folder.
- Move the files to Solution root.
- Create a Solution folder named "Solution Items".
- Add all the files just moved to that solution folder.
- 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