batch.scripts icon indicating copy to clipboard operation
batch.scripts copied to clipboard

Suggestion for better and faster .net batch prologue

Open SergeAgeyev opened this issue 5 years ago • 0 comments

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%

*/

SergeAgeyev avatar Nov 21 '19 15:11 SergeAgeyev