I am new to Nuget package development and i have successfully created a few simple packages that place files at the root level of a project. However, for these packages to work out of the box. I need the files to be placed in specific folders within the target project. See examples below...
LoginController.cs would be placed into "Controllers" folder in clients mvc project. Login.cshtml would be placed into "Views/Login" folder in clients mvc project.
Is there a way to achieve this specific output? Anytime i install a javascript library, it always defaults to the "Scripts" folder so either that is built in Nuget runtime or the publishers of the package are telling it to use that location.
NuGet provides three hooks for you to write PowerShell scripts and include them in your package.
Init.ps1
- this runs when the package is first installed at the solution levelInstall.ps1
- this runs when the it gets installed at the project levelUninstall.ps1
- this runs when the package is uninstalledIt's important to note that Install.ps1
and Uninstall.ps1
are no longer supported in Visual Studio 2017.
To add these files, you simply update your NuSpec file similar to this:
<?xml version="1.0"?>
<package >
<metadata>...</metadata>
<files>
<file src="scripts\NugetScripts\Init.ps1" target="tools\Init.ps1" />
</files>
</package>
Your PowerShell file will need the following parameters declaration:
param($installPath, $toolsPath, $package, $project)
From there, you will be able to modify the project and add/edit files to your hearts content. Here is a blog post that provides additional details, but there are plenty more examples on the web if you Google around. It just depends on what kinds of things you want to do in script.