Nuke Build 声明一个作为构建的一部分获取的工具

Nuke Build declare a tool that is fetched as part of the build

我使用的大多数工具都是从 csproj 文件引用并由 nuget 自动获取的 dotnet 工具。 一些工具是老式的Framework工具,使用前应将其复制到tools目录中。 对于后者,我有一个 GetTools 目标。

我的问题是声明工具:

 [LocalExecutable("./tools/MyFrameworkTool.exe")] 
 readonly Tool FrameworkTool;

这会引发以下断言:

Assertion failed: File.Exists(C:\Jenkins\workspace\Job\./tools/MyFrameworkTool.exe)

FrameworkTool 为空。

当 GetTools Target 获取工具时,我如何对工具进行 'late' 声明?

其他开发者遇到同样情况,我post这里回答。

Matthias 建议使用 ToolResolver 是关键。

初始(恢复)Target可以将工具复制到./tools/MyCustomTool目录。

使用 ToolResolver static class,可以在 Target 中声明它,引用它的地方:

Tool MyCustomTool = ToolResolver.GetLocalTool("./tools/MyCustomTool/MyCustomTool.exe");

MyCustomTool 现在可以在此 Target 中使用。