11

I am having trouble with ps script in init.ps1 of nuget package. I am trying to create a solution folder upon install of the package AND then copy dlls/pdbs to this folder (and delete the source dll/pdbs installed by the package in the project). I am able to create the solution folder, but am having trouble copying the files from the \content\temp directory to the solution folder. In fact, i really want a real folder on the filesystem and a solution folder to match, so the copy should copy the files to the real file system folder and then be added to the solution folder.
The copy portion is not working and I am not getting any output errors. Bit lost.

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

# Get the open solution.
$solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])

# Create the parent solution folder.
$parentProject = $solution.AddSolutionFolder("MyDlls")

# Create a child solution folder.
$parentSolutionFolder = Get-Interface $parentProject.Object ([EnvDTE80.SolutionFolder])

$fileName = (Join-Path $installPath "\temp\mydll")
$projectFile = $parentSolutionFolder.AddFromFile($fileName)

Write-Host ""
Write-Host $sourcePath
Write-Host $parentSolutionFolder
MrMVCMan
  • 490
  • 2
  • 7
  • 20
  • Out of interest, what are the paths you're passing to $installPath and $toolsPath – mitchimus Feb 26 '14 at 06:13
  • @mitchimus these paths are passed by NuGet Powershell environment and correspond to the absolute path where the package is installed (a directory in the "packages" directory, which is in the same directory as the solution file) and the path to the "tools" folder in $installPath, respectively. – ygormutti Sep 15 '15 at 16:42

1 Answers1

10

I had the same issue and found a PowerShell script in the BuildDeploySupport project that did exactly this. All you need to do is update the name of the folder you'd like to copy in (Deploy\Support in the ps1 linked below) in several places.

See BuildDeploySupport Solution Folder Copy Init.ps1

From link (as of 30/11/2017):

param($installPath, $toolsPath, $package)

# find out where to put the files, we're going to create a deploy directory
# at the same level as the solution.

$rootDir = (Get-Item $installPath).parent.parent.fullname
$deployTarget = "$rootDir\Deploy\Support\"

# create our deploy support directory if it doesn't exist yet

$deploySource = join-path $installPath 'tools/deploy'

if (!(test-path $deployTarget)) {
    mkdir $deployTarget
}

# copy everything in there

Copy-Item "$deploySource/*" $deployTarget -Recurse -Force

# get the active solution
$solution = Get-Interface $dte.Solution ([EnvDTE80.Solution2])

# create a deploy solution folder if it doesn't exist

$deployFolder = $solution.Projects | where-object { $_.ProjectName -eq "Deploy" } | select -first 1

if(!$deployFolder) {
    $deployFolder = $solution.AddSolutionFolder("Deploy")
}

# add all our support deploy scripts to our Support solution folder

$folderItems = Get-Interface $deployFolder.ProjectItems ([EnvDTE.ProjectItems])

ls $deployTarget | foreach-object { 
    $folderItems.AddFromFile($_.FullName) > $null
} > $null
Adam Houldsworth
  • 63,413
  • 11
  • 150
  • 187
mshish
  • 346
  • 2
  • 6
  • 1
    Turns out that script isn't recursive, but making it recursive is easy. Modify line 36 to read: `ls -recurse $deployTarget | foreach-object { ` – mshish Mar 17 '14 at 16:42
  • 3
    Please copy in the relevant pieces (leave the link as attribution). Web sites have been known to disappear and even change over time. – Chris Pfohl Aug 29 '14 at 13:50