Search code examples
nuke-build

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

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