Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

When inspecting reported issues for the web applications we create, it's always good to know which version of the application you're actually looking at. Knowing things like the TFS path, which includes the branch path, changeset, time of build, etc. can help you determine what the problem is.

We thought up a simple batch script, that is called from the post-build event (_build.cmd):
@echo off
::
:: Script to generate build information.
:: Place the following in the post-build event of the Visual Studio project:
:: ---------------------------------
:: cd "$(ProjectDir)"
:: _build.cmd "$(DevEnvDir)..\tools\vsvars32.bat" "$(ConfigurationName)" "$(SolutionDir)" "$(ProjectDir)" > _build.txt
:: ---------------------------------
::

call %1
echo.
echo Build information generated %25DATE% %TIME% by %USERNAME%
echo.
echo Build       = %2
echo SolutionDir = %3
echo ProjectDir  = %4
echo.
if not %2 == "Release" goto notrelease
	echo TFS Path:
	for /f "delims=:" %%a in ('tf dir %3') do (
		echo %%a
		goto break
	)
	:break
	echo.
	echo Changelog:
	tf history %3 /recursive /format:Brief /noprompt
	goto :eof

:notrelease
echo TFS details are only generated in 'Release'

Post-build command:
cd "$(ProjectDir)"
_build.cmd "$(DevEnvDir)..\tools\vsvars32.bat" "$(ConfigurationName)" "$(SolutionDir)" "$(ProjectDir)" > _build.txt

When building in Release mode, the script will generate a _build.txt file that can be deployed with the build to the remote server that runs the web application. Example output:
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

Build information generated vr 13-01-2012  9:10:04,00 by m.wensveen

Build       = "Release"
SolutionDir = "D:\klanten\MySolution_Website\MySolution_Web\"
ProjectDir  = "D:\klanten\MySolution_Website\MySolution_Web\Website\"

TFS Path:
$/MySolution_Website/MySolution_Web

Changelog:
Changeset User          Date       Comment
--------- ------------- ---------- --------------------------------------------
45042     m.wensveen    12-1-2012  Include build.txt in project, but exclude fr
45008     m.wensveen    11-1-2012  post-build event command to generate build.t
44676     m.wensveen    4-1-2012   don't crash when there are no search results
44670     m.wensveen    4-1-2012   supportcall 24713 yo dawg i herd you like su

You might want to include the _build.txt file in your project so that when you publish the website, this file comes along. However, you might not want this file in TFS. You can exclude the file (after including it in you project) under File > Source Control > Exclude _build.txt from Source Control.

My advise it not to publish the _build.txt file to production servers, for security reasons. But on all other environments it can be very helpful.

Enjoy! Matthijs

 © Evident Interactive BV