How to setup buildcount and build date for Visual studio 2013 projects
In the old visual studio you could add (working, count++) build count and build date via macros but it is not available in 2013 anymore and you have to do it with dos batch files.
Setup batch files
First add two files called build.bat and date.bat to your chosen location (c:\yourpath\ here).
Open c:\yourpath\build.bat in editor and copy paste following into it:
--@echo off cd %1 if not exist %1build.count >%1build.count echo 0 for /f %%x in (%1build.count) do ( set /a var=%%x+1 ) >%1build.count echo %var%del %1%2.buildcount echo|set /p=build > %1%2.buildcount type %1build.count >> %1%2.buildcount goto:eof
It simply will take two parameters, path and name. It will create p2.count file that it reads and increments via every run. In the end it copies it and “build ” word to new file called p2.buildcount.
c:\yourpath\date.bat should contain:
date /t > %1\%2.buildtime exit 0
And it will simply pipe date /t into p2.buildtime and exit graciously with zero.
Configure prebuild events in visual studio
After this configure your projects in visual studio under Build events type these two things into Pre-build event command line box:
call "c:\yourpath\build.bat" $(ProjectDir) $(ProjectName) call "c:\yourpath\date.bat" $(ProjectDir) $(ProjectName)
Configure your project
Build your code once to create the files and add the file to your project:
Then under file properties set it to be embedded resource
Do the same for project.buildtime.
Retrieve embedded resource inside your code
Inside your code, where you need to retrieve the data:
string build = GetResourceContent("project.buildtime");
string buildtime = GetResourceContent("project.buildtime");
and use them as you wish. Voila! You have build count and date!