Skip to content

Suggestion for better and faster .net batch prologue #25

Open

Description

@SergeAgeyev

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%

*/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions