npocmaka / batch.scripts

batch script utils and examples by npocmaka -
https://www.linkedin.com/in/npocmaka/
MIT License
1.08k stars 873 forks source link

Suggestion for better and faster .net batch prologue #25

Open SergeAgeyev opened 5 years ago

SergeAgeyev commented 5 years ago

There is some suggestions to improvement on .net batch prologue. (as a source screenCapture.bat was used)

  1. If screenCapture.exe already exist, better to call immediately, skipping search for csc.exe
  2. screenCapture.bat produces screenCapture.exe at the place where it called, not where screenCapture.bat is located. if called from multiple laces produces many screenCapture.exe
  3. if you call it from "another.bat" file located in the same folder using "sibling" pattern "call %0..\screenCapture", it will not compile (as ".bat" extension may not be added to "%0" inside screenCapture.bat under Win7)

Here is updated prologue I use:

// 2>nul||@goto :batch
/*
:batch
@echo off
if exist "%~dpn0.exe" (
"%~dpn0.exe" %*
exit /b %errorlevel% 
)

setlocal
:: find csc.exe
set "csc="
for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do  set "csc=%%#"

if not exist "%csc%" (
   echo no .net framework installed
   exit /b 10
)

call %csc% /nologo /r:"Microsoft.VisualBasic.dll" /out:"%~dpn0.exe" "%~dpn0.bat" || (
   exit /b %errorlevel% 
)

"%~dpn0.exe" %*
endlocal & exit /b %errorlevel%

*/