0

I'm investigating ways to allow many website projects to pull from the same collection of CSS/JS/HTML and have that collection be updated once and then delivered to all the projects that use it.

At the moment, I'm exploring using a NuGet package (my company uses TFS and VS so it seems the logical package manager) to deliver the styles, and using the content folder to deliver the files directly into the project. However, each project is going to need those files in different locations in order to work properly.

Is there a way to add a custom script to a post-install/update of a NuGet package for each project?

xmakina
  • 11
  • 2
  • NUGET packages allow you run powershell scripts after installation, see [this](http://www.vicesoftware.com/nuget/creating-a-nuget-package-that-will-install-files-relative-to-the-solution/). – Cheng Chen Aug 19 '16 at 08:14
  • Could I use that to get it to execute a script in the project it's just been installed into? The post-install needs to be project specific, a bit like the npm postinstall script – xmakina Aug 19 '16 at 09:16

1 Answers1

1

For those of you in the future:

In your package: tools/install.ps1

param($installPath, $toolsPath, $package, $project)
$projectFullName = $project.FullName
$debugString = "install.ps1 executing for " + $projectFullName
Write-Host $debugString

$fileInfo = new-object -typename System.IO.FileInfo -ArgumentList $projectFullName
$projectDirectory = $fileInfo.DirectoryName
$customInstallFile = $projectDirectory + "\" + $package.Id + ".ps1"
Write-Host "looking for" $customInstallFile 

if(Test-Path $customInstallFile){
    Write-Host "found it"
    & $customInstallFile
} else {
    Write-Host "not found"
}

Write-Host "Installation Complete"

And in your project's root folder: [packageId].ps1

Write-Host "Hello world!"
xmakina
  • 11
  • 2
  • Thanks for sharing your solution here. Please mark your answer which is benefit to other communities who has the same problem. – Weiwei Aug 22 '16 at 01:22