visual-studiotfspackagenugetpost-install

Can I add a custom step to a nuget install


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?


Solution

  • 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!"