There is an easy way to keep tabs about what code is on each environment. There is a good MSBuild project which provides a set of useful additional MSBuild tasks:
https://github.com/loresoft/msbuildtasks
To reference the extra tasks, you will need to make sure you have referenced the MSBuild Community Tasks Project DLL. The tasks of interest are GitVersion and GitBranch which will provide details of the SHA and branch that is being deployed. The following target is what you need to get started:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<Target Name="TcGitVersionInformation"> <GitVersion ContinueOnError="WarnAndContinue"> <Output TaskParameter="CommitHash" PropertyName="GitDeployedCommitHash" /> </GitVersion> <GitBranch ContinueOnError="WarnAndContinue"> <Output TaskParameter="Branch" PropertyName="GitDeployedBranch" /> </GitBranch> <ItemGroup> <GitVersionInformationFile Include="$(ConfigurationOutput)/App_Config/__DeployInfo"/> <GitVersionInformationLine Include="Deployment Date: $([System.DateTime]::Now)" /> <GitVersionInformationLine Include="Deployed by: $(USERNAME)" /> <GitVersionInformationLine Include="Git Branch: $(GitDeployedBranch)" /> <GitVersionInformationLine Include="Git Version: $(GitDeployedCommitHash)" /> </ItemGroup> <WriteLinesToFile File="@(GitVersionInformationFile)" Lines="@(GitVersionInformationLine)" Overwrite="true" /> </Target> |
This will generate a file to App_Config/__DeployInfo which will look something like:
1 2 3 4 |
Deployment Date: 22/12/2014 17:02:11 Deployed by: Mr Deployer Git Branch: sprint Git Version: b4bc2b4 |
Similar functionality could be added for Mercurial but isn’t included in this project, the following could be useful: https://msbuildhg.codeplex.com/documentation