7

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?

TheRoadrunner
  • 1,281
  • 14
  • 34
  • http://www.nuke.build/docs/authoring-builds/cli-tools.html first note. dotnet tools are no exception. – Matthias Jul 04 '20 at 02:02
  • @Matthias thanks for your feedback, and sorry for being a noob, but does this get the tool installed in my build directory? I would really appreciate a working sample. :-) – TheRoadrunner Jul 04 '20 at 10:09
  • Including the to the project file DOES get the package downloaded to ~\.nuget\packages\packageId\version\tools\netcoreapp2.1\any, but as dll's I have no Idea how to invoke the tool. With dotnet tool install (--global) I get a .exe that I can invoke as a Tool from Nuke. But I DO prefer a (local) install of a specific version. – TheRoadrunner Jul 04 '20 at 10:28
  • There is no need to install a global tool when it is used from a build. The dll can be invoked just as any other executable. – Matthias Jul 04 '20 at 14:29
  • It is only easy, when you know how. Maybe I am an idiot, but I don't – TheRoadrunner Jul 04 '20 at 15:19
  • I just explained something?! – Matthias Jul 04 '20 at 15:57

2 Answers2

4

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.

TheRoadrunner
  • 1,281
  • 14
  • 34
  • I guess the solution I tried in the question was close to the solution, had I only realized that there is no .exe (which is a product of dotnet tool install), but the Personal Access Token used in my nuget.config was expired, which derailed me completely. – TheRoadrunner Jul 05 '20 at 14:19
3

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>
Aage
  • 5,932
  • 2
  • 32
  • 57