2

I have nuget package with command line tools that I want to invoke from pre-build event in VS2015 project.

I could use relative path to invoke command from package folder but then I have to modify that path if either nuget package version or package folder changes. Is there an easier way to do this?

Optional Option
  • 1,521
  • 13
  • 33
  • not really. unless you add your tools to the project as content. Which isn't recommended. – jessehouwing Oct 07 '16 at 19:10
  • Grpc.Tools nuget package drops bunch of command line tools in nuget folders. Seems weird to pack everything in nuget without easy way to use them. – Optional Option Oct 07 '16 at 19:27
  • The trick would be to update the project file with the right path on install and upgrade. Just add a target with a specific name, that way you'd be able to remove it and re-add it every time the version changes. It's just the way it is. Some things aren't easy. – jessehouwing Oct 08 '16 at 09:01

1 Answers1

2

You could create a batch file in your project root to call your tools, which is similar with below script. More detailed information about use a tool installed by Nuget in your build scripts, please refer to:

https://lostechies.com/joshuaflanagan/2011/06/24/how-to-use-a-tool-installed-by-nuget-in-your-build-scripts/

@ECHO OFF 
SETLOCAL

FOR /R %~dp0\source\packages %%G IN (nunit-console.exe) DO ( 
 IF EXIST %%G ( 
  SET TOOLPATH=%%G 
  GOTO FOUND 
  ) 
) 

IF '%TOOLPATH%'=='' GOTO NOTFOUND 

:FOUND 
%TOOLPATH% %* 
GOTO :EOF 

:NOTFOUND 
ECHO nunit-console not found. 
EXIT /B 1
Weiwei
  • 3,674
  • 1
  • 10
  • 13
  • This is the best solution so far. Only minor modifications were needed for my project. Surprised that nuget had to be "hacked" for this use case. – Optional Option Oct 10 '16 at 18:04