在我的 nuget 包安装后执行一个操作 [英] Execute an action after my nuget package is installed

查看:55
本文介绍了在我的 nuget 包安装后执行一个操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经创建了很多 NuGet 包.其中之一是一个工具,它包含一个特殊的编译器,并且像 dotnet 工具 一样安装.命令的名称是PolyGen".

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".

我们使用了与 Grpc.Tools 使用的机制类似的机制,这意味着我们已经在 NugetPackage 中定义了 .targets 文件.它运作良好.

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

但是当我更新 PolyGen 时,之后我必须使用 dotnet tool update 命令手动更新 dotnet 工具.

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

但是我看到当Grpc.Tools 更新时,dotnet 工具更新会自动执行.包管理器控制台写了以下消息:

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?

谢谢你们!

推荐答案

您可以使用 init.ps1 powershell 脚本来完成此任务.每次在目标机器上安装软件包后都会执行此脚本.

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

只需在包定义的 tools/ 文件夹中使用以下内容创建文件 init.ps1:

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.

但请注意,init.ps1每次打开解决方案时都会执行.如果您只需要在 NuGet 包安装后执行一次 - 您可以插入条件参数并将其值存储在您的包安装文件夹中(例如在文件中).

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).

这篇关于在我的 nuget 包安装后执行一个操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆