public
Last active

Example batch file to execute a tool from a Nuget package

  • Download Gist
nuget_tool.bat
Batchfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
@ECHO OFF
SETLOCAL
REM This can be used for any .exe installed by a nuget package
REM Example usage: nuget_tool.bat nunit-console.exe myproject.tests.dll
SET TOOL=%1
FOR /R %~dp0\source\packages %%G IN (%TOOL%) DO (
IF EXIST %%G (
SET TOOLPATH=%%G
GOTO FOUND
)
)
IF '%TOOLPATH%'=='' GOTO NOTFOUND
 
:FOUND
%TOOLPATH% %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
 
:NOTFOUND
ECHO %TOOL% not found.
EXIT /B 1
nuget_tool.rb
Ruby
1 2 3 4 5
# Usage: nunit_path = tool "NUnit", "nunit-console.exe"
 
def tool(package, tool)
File.join(Dir.glob(File.join(package_root,"#{package}.*")).sort.last, "tools", tool)
end
nunit.bat
Batchfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
@ECHO OFF
SETLOCAL
REM You might prefer specific scripts for each tool. Makes the usage a bit easier. This is an example for NUnit.
 
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.