Skip to content

Instantly share code, notes, and snippets.

@blacktaxi
Created September 17, 2013 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blacktaxi/6592601 to your computer and use it in GitHub Desktop.
Save blacktaxi/6592601 to your computer and use it in GitHub Desktop.
Shell script to sign a .NET assembly.
@echo off
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe" -q -vf "%1" > NUL
if ERRORLEVEL 1 goto NOT_SIGNED
:SIGNED
echo Already signed: %~nx1
goto END
:NOT_SIGNED
echo Signing %~nx1...
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ildasm.exe" /out="%~dpn1.il" "%1"
if ERRORLEVEL 1 goto FAILED
if EXIST "%~dpn1.res" (
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\ilasm.exe" /dll /key="%2" /resource="%~dpn1.res" "%~dpn1.il"
) else (
"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\ilasm.exe" /dll /key="%2" "%~dpn1.il"
)
if ERRORLEVEL 1 goto FAILED
rem Verify...
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe" -q -vf "%1" > NUL
if ERRORLEVEL 1 goto FAILED
echo "Successfully signed."
goto END
:FAILED
echo Failed to sign %~nx1
:END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment