Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute an action after my nuget package is installed

We have created a lot of NuGet packages. One of them is a tool, and it contains a special compiler and it is installed like a dotnet tool. The name of the command is "PolyGen".

We used a similar mechanism to what Grpc.Tools uses, that means we have defined .targets file inside our NugetPackage. And it works well.

But when I update my PolyGen, afterwards I have to update the dotnet tool manually with dotnet tool update command.

But I see when the Grpc.Tools is updated, the dotnet tool update is automatically executed. And the Package Manager console wrote the following message:

Executing nuget actions took 181,36 ms

How can we define this automatically executed command, to avoid a manual update?

Thank you guys!

like image 622
György Gulyás Avatar asked Sep 29 '19 18:09

György Gulyás


People also ask

What happens when a NuGet package is installed?

NuGet creates a subfolder for each package identifier, then creates subfolders for each installed version of the package. NuGet installs package dependencies as required. This process might update package versions in the process, as described in Dependency Resolution.

How do I run a NuGet package restore in Visual Studio?

Restore packages manually using Visual StudioEnable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.


1 Answers

You can use init.ps1 powershell script to accomplish this task. This script executing every time after package installed on targeted machines.

Just create file init.ps1 in tools/ folder of your package definition with this content:

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

# Write all required actions on powershell here.

But be aware of that init.ps1 also executing every time when solution opens. If you need to execute it only one time after NuGet package installation - you can insert condition parameter and store it's value inside your package installation folder (e.g. in file).

like image 115
picolino Avatar answered Nov 04 '22 02:11

picolino