Reputation: 2905
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:
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.
Upvotes: 11
Views: 2149
Reputation: 7658
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://learn.microsoft.com/en-us/dotnet/core/tools/global-tools
Upvotes: 2
Reputation: 156
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.
Upvotes: 1
Reputation: 1
This might help you -> http://lostechies.com/joshuaflanagan/2011/06/24/how-to-use-a-tool-installed-by-nuget-in-your-build-scripts/
I used the solution with the wildcard in the 'CD' command, so my postbuild looks like this:
CD "$(SolutionDir)packages\ToolName*\tools"
MyTool.exe
Upvotes: -2