diff --git a/.gitignore b/.gitignore
index 9a44da1..4adf81b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
.vs/
build/
+version.h
diff --git a/WinChat/PreBuild.bat b/WinChat/PreBuild.bat
new file mode 100644
index 0000000..0e1951c
--- /dev/null
+++ b/WinChat/PreBuild.bat
@@ -0,0 +1,48 @@
+@echo off
+
+echo [Pre Build] Startup
+
+::Set Version
+echo [Pre Build] Setting version...
+
+::First make sure git is in the path
+where git >nul 2>&1
+if %errorlevel% neq 0 goto noGit
+goto yesGit
+
+:noGit
+echo [Pre Build] Error: git not found on PATH!
+exit 1
+
+::We have git on the command line, so set the version string
+:yesGit
+git describe HEAD > temp1
+git branch --show-current > temp2
+set /p commit= < temp1
+set /p branch= < temp2
+del temp1
+del temp2
+
+::If the current branch is stable, don't include it in the version string
+if "%branch%" == "stable" goto noBranch
+
+set version=%commit%+%branch%
+goto testOutput
+
+:noBranch
+set version=%commit%
+
+::Don't touch the version file if it's already up to date
+:testOutput
+set /p oldVersion= < src\version.h
+if "%oldVersion%" == "#define APPVERSION "%version%"" goto sameVersion
+
+echo #define APPVERSION "%version%"> src\version.h
+goto continue
+
+:sameVersion
+echo [Pre Build] Same version
+
+:continue
+echo [Pre Build] Exit
+exit
\ No newline at end of file
diff --git a/WinChat/WinChat.vcxproj b/WinChat/WinChat.vcxproj
index 75cbe83..9aedcb2 100644
--- a/WinChat/WinChat.vcxproj
+++ b/WinChat/WinChat.vcxproj
@@ -64,6 +64,9 @@
Console
true
+
+ PreBuild.bat
+
@@ -82,6 +85,9 @@
true
true
+
+ PreBuild.bat
+
diff --git a/WinChat/src/main.cpp b/WinChat/src/main.cpp
index 4182b9e..659a88e 100644
--- a/WinChat/src/main.cpp
+++ b/WinChat/src/main.cpp
@@ -1,7 +1,11 @@
#include
+#include "version.h"
+
+#define APPNAME "WinChat"
+
int main(int argc, char* argv[]) {
- std::printf("WinChat\n");
+ std::printf(APPNAME " " APPVERSION "\n");
std::cin.get();
return EXIT_SUCCESS;