'How to install dotnet tool with nuke

I am new to Nuke, trying to transition from Cake to Nuke. In Cake I have the option to install (locally) tools with:

#module nuget:?package=Cake.DotNetTool.Module&version=0.3.0

and

#tool dotnet:?package=my.package.id&version=1.0.1

I have tried this in Nuke:

[PackageExecutable(
    packageId: "my.package.id",
    packageExecutable: "mypakagedtool.exe",
    Version = "1.0.1")]
readonly Tool MyPackagedTool;

but that returns a:

Assertion failed: Could not find package 'my.package.id' (1.0.1) using:
 - Project assets file 
 - NuGet packages config

I guess this is not for dotnet tools, but for nuget tools?



Solution 1:[1]

The way I made it work, was to include this in the build.csproj:

  <ItemGroup>
    <PackageDownload Include="MyPackageId" Version="[1.0.1]" />
  </ItemGroup>

and in Build.cs:

[PackageExecutable("MyPackageId", "MyTool.dll")] readonly Tool MyTool;

then the tool can be invoked with:

MyTool("arguments");

...and of course nuget.config should be setup to give access to the package repository.

Solution 2:[2]

Within Nuke Build you can do the following (this example is for OctopusTools):

nuke :addpackage OctopusTools

This results in the this <ItemGroup/> element being added to the .csproj of the Build (Nuke) project:

<ItemGroup>
    <PackageDownload Include="OctopusTools" Version="[9.0.0]" />
</ItemGroup>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TheRoadrunner
Solution 2 Aage