-
-
Save mattuu/c239e124d40b239cf32da75b7b6db3c5 to your computer and use it in GitHub Desktop.
Run MSBuild and MSTest for C# project from git pre-commit hook
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
#!/bin/sh | |
# Helper | |
safeRunCommand() { | |
typeset cmd="$*" | |
typeset ret_code | |
echo cmd=$cmd | |
eval $cmd | |
ret_code=$? | |
if [ $ret_code != 0 ]; then | |
printf "Error : [%d] when executing command: '$cmd'" $ret_code | |
exit $ret_code | |
fi | |
} | |
# Path To MSBuild.exe | |
MSBuild="/c/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe" | |
# Path To MSTest.exe | |
MSTest="/d/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio\ 11.0/Common7/IDE/MSTest.exe" | |
# Get Project root path (without tailing /) | |
ProjectRoot="$(git rev-parse --show-toplevel)" | |
# Test Containers (without leading /) | |
Tests=( | |
"ConsoleSharp.Tests/bin/Debug/ConsoleSharp.Tests.dll" | |
"Mirror.Test/bin/Debug/Mirror.Test.dll" | |
) | |
# Build | |
safeRunCommand $MSBuild $ProjectRoot/ConsoleSharp.sln | |
# Test | |
Args=("${Tests[@]/#//testcontainer:$ProjectRoot/}") | |
safeRunCommand $MSTest $(eval 'echo "${Args[*]}"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment