Last active
August 2, 2016 16:20
-
-
Save dck-jp/8b989a83b7df8ccab5c3 to your computer and use it in GitHub Desktop.
Execute C# code directly on Windows by double-clicking the source file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
SET OutputCs="TempCs.cs" | |
SET OutputExe="TempCs.exe" | |
if exist %OutputCs% goto ExecuteCs | |
del %OutputCs% | |
for /f "usebackq skip=20 delims=|" %%i in (%0) do (echo %%i>>%OutputCs%) | |
:ExecuteCs | |
pushd %~dp0 | |
FOR /F "TOKENS=1,2,*" %%I IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework" /v "InstallRoot"') DO IF "%%I"=="InstallRoot" SET FrameworkPath=%%K | |
SET PATH="%PATH%;%FrameworkPath%v4.0.30319\;%FrameworkPath%v3.5;%FrameworkPath%v3.0;" | |
csc /nologo /out:%OutputExe% %OutputCs% | |
if %ERRORLEVEL% NEQ 0 goto ExecuteFAILURE | |
echo __________ Execute Compiled Cs File Inside Bat File _________________ | |
%OutputExe% | |
del %OutputExe% %OutputCs% | |
exit | |
:ExecuteFAILURE | |
%0 | |
exit | |
REM ========== Write your C# code below this line ============== | |
using System; | |
namespace Test | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello, World!!"); | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment