The idea is simple and could be applicable with any kind of project and version control. The pre-build step should run the script which get history for project folder, preserving only last record. Than run status check to expose files modified after check-out. The output is embedded into rendered service code.
Sample for WCF service generated from TFS output:
set path=%path%;%1% set outFile=%~dp0ClassFiles\Revision.cs echo using System.ServiceModel.Web;using System.ServiceModel;using System.ServiceModel.Activation; >%outFile% echo namespace BSA_EventPlanner.ClassFiles >>%outFile% echo { [ServiceContract][System.ServiceModel.Activation.AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] >>%outFile% echo public class Revision >>%outFile% echo { [WebInvoke(UriTemplate = "/", Method = "GET", ResponseFormat = WebMessageFormat.Xml)] >>%outFile% echo public string EntitieList() >>%outFile% echo { var s = @^" >>%outFile% tf history %~dp0 /stopafter:1 /recursive /format:brief /noprompt >>%outFile% tf status %~dp0 /recursive >>%outFile% echo ^";return s;}}} >>%outFile%
The rendered code will look like:
using System.ServiceModel.Web; using System.ServiceModel; using System.ServiceModel.Activation; namespace BSA_EventPlanner.ClassFiles { [ServiceContract] [System.ServiceModel.Activation.AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Revision { [WebInvoke(UriTemplate = "/", Method = "GET", ResponseFormat = WebMessageFormat.Xml)] public string EntitieList() { var s = @" ";return s;}}}
The string is empty if TFS is not available, otherwise it will be filled with revision and modified files list.
Do not forget to add the WCF routing and ClassFiles\Revision.cs file to project.
Happy coding!