Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deliver command-line tool via NuGet for use in post-build events in Visual Studio

I've developed a command-line utility that takes .NET assemblies as input and generates XML as output for use by another product.

Ideally I'd have it:

  • Delivered via NuGet as a solution-level package
  • Accessible in post-build events at the project level
  • Bit where I'm stuck: Accessible in that post-build event just by specifying the command name without path
    • i.e. MyTool.exe /i $(TargetPath) as opposed to ..\packages\ToolName-1.0.0.0\tools\MyTool.exe /i $(TargetPath)

The first two things I can already do, and a post-build event command as above works just fine but only if I first open the Package Manager Console (even if I don't type any commands, just have to open it) - seemingly it's doing something cool with paths when it fires up so that I don't have to specify the ..\packages\ToolName-1.0.0.0\tools\MyTool.exe.

Is it possible for my NuGet package to use an Init.ps1 script (or some other mechanism) to adjust paths so that I needn't specify the full relative path to the tool when writing a post-build event, or to otherwise include run tool as a post-build step automatically?

Note - I accept NuGet mightn't be the ideal vector for delivering this sort of tool, but it would be convenient.

like image 439
Pablissimo Avatar asked Jan 04 '13 18:01

Pablissimo


2 Answers

Just for the folks that come across this;

I've seen people use a nuget package for this, e.g. see nswag.msbuild: https://github.com/RicoSuter/NSwag/wiki/NSwag.MSBuild

In short the nuget package contains the tool as a command line utility executable. It also defines some buildprops that define the path to this tool (something along the lines of /packages/myToolNugetPkg/mytool.exe) Then you can use this property in an msbuild task.

Also .NET core supports 'tools', which is exactly what you needed:

https://docs.microsoft.com/en-us/dotnet/core/tools/global-tools

like image 74
sommmen Avatar answered Nov 12 '22 19:11

sommmen


Chocolatey (which technically qualifies as using NuGet) has a very cool magical "shimming" facility.

In brief, any executable in your package will be available on the PATH automatically. It's very cool.

like image 40
Joshua Thornton Avatar answered Nov 12 '22 17:11

Joshua Thornton