Search code examples
visual-studio-2015nugetpre-build-event

Invoking executable from nuget package folder in pre-build event in VS2015


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?


Solution

  • 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