NuGet - install.ps1 does not get called

Viewed 14583

I'm trying to create my first NuGet package. I don't know why my install.ps1 script does not get called. This is directory structure

--Package
|
 - MyPackage.nuspec
 - tools
 |
  - Install.ps1
  - some_xml_file

I build package using this command line nuget.exe pack MyPackage.nuspec

When I Install-Package from VS Package Manager Console install.ps1 does not get called.

I thought that maybe I had some errors in script and that's the reason so I commented out everything but

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

But I don't see ECHO appearing in Package Manager Console. What can be wrong?

3 Answers

An alternative to the install script can sometimes be a package targets file. This targets file is automatically weaved into the project file (csproj, ...) and gets called with a build.

To allow Nuget to find this targets file and to weave it in, these two things are mandatory:

  • the name of the targets file must be <package-name>.targets
  • it must be saved in the folder build at the top level of the package

If you like to copy something to the output folder (e.g. some additional binaries, like native DLLs) you can put these binaries into the package under folder binaries and use this fragment in the targets file for the copying:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="CopyBinaries" BeforeTargets="BeforeBuild">
        <CreateItem Include="$(MSBuildThisFileDirectory)..\binaries\**\*.*">
            <Output TaskParameter="Include" ItemName="PackageBinaries" /> 
        </CreateItem>

        <Copy SourceFiles="@(PackageBinaries)"
              DestinationFolder="$(OutputPath)\%(RecursiveDir)"
              SkipUnchangedFiles="true"
              OverwriteReadOnlyFiles="true"
        />
    </Target>
</Project>
Related