The solution I came up with as baseline answer for this question is to turn the C# file into a "polyglot" *.cs.bat
file that runs the full compile command on top of the C# source code.
/*? 2>NUL & @echo off
echo.
echo COMPILING...
"%ProgramFiles(x86)%\MICROS~3\2017\ENTERP~1\MSBuild\15.0\Bin\Roslyn\csc.exe" ^
/target:library /out:fx1.dll fx1.cs.bat ^
/reference:"C:\blah\blah\Microsoft.JScript.dll" ^
/reference:"C:\astor\loads\better\ease\zog.dll"
PAUSE
GOTO:EOF REM */
// C# program...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
// blah...
To compile I can just run fx1.cs
or fx1.cs.bat
. That certinly is practical.
This may be useful but the downsides are at least these:
text highlighting is lost in the various editors that have it for *.cs
files... If only there was a (easy) way to run *.cs files as batch (type file | cmd
seems to ignore PAUSE
, EXIT /B
, EXIT
, GOTO:EOF
)
The compiler path is hardcoded (but I think it can be determined with more batch fiddling)
It tries to run /*.exe
, so the first line always gives me an error because I found no way to avoid it being run, so I can only put a ?
in there (so it should not be a valid path ever) and hide it with error redirection.
While it is unpractical to edit in an IDE, I think this may be an easy format for distribution of simple utilities.
I'm not very good at this... so if someone has better ideas (for the polyglot route) please improve this answer by commenting or editing it.