Our team of developers and testers at Dot Net Architect maintain multiple applications for our many clients, of which any number could be in active development, in peer review, in testing, or packaged for release at any given time.
To manage these applications, we use the Branching and Merging feature in Microsoft’s Team Foundation Server with several branches for active development, peer review, testing and release, each with their own version numbers to keep track of progress. Look out for a future post detailing exactly how we achieve this!
To keep track of everything, we have found it’s very useful to visibly record each application’s version number, build date and development details, such as the branch name and connection string, in the footer to make it obvious which version is currently being used.
To accomplish this, we add two labels to the Footer.ascx page through Iron Speed Designer, called VersionNumber and BuildDetails, which will display these details during run-time.
In the web configuration (web.config), we add the following key-value pair to name the branch.
<add key="FooterDescription" value="Trunk" />
In the Footer.ascx.cs control, we then add the following code to the LoadData function to get the version number and build details then display the results on these labels.
public void LoadData()
{
// LoadData reads database data and assigns it to UI controls.
// Customize by adding code before or after the call to LoadData_Base()
// or replace the call to LoadData_Base().
LoadData_Base();
if (!Page.IsPostBack)
{
VersionNumber.Text = DNAVersionUtils.GetVersionNumber();
BuildDetails.Text = string.Format("{0}<br />{1}", DNAVersionUtils.GetBuildDate(), DNAVersionUtils.GetDevelopmentDetails());
}
}
We have a custom DNAUtils.cs class file in the App_Code folder containing our application-specific customisations, and to this, we add the following DNAVersionUtils class.
Note that if the FooterDescription key-value pair is not in the web configuration, then the development details will not be displayed. This allows us to display these details on our local systems during development, but not on the production system as the key is not added to the production configuration file.
#region "DotNetArchitect - Version Utilities"
public class DNAVersionUtils
{
public static string GetVersionNumber()
{
Version applicationVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
return string.Format("v{0}.{1}.{2}", applicationVersion.Major, applicationVersion.Minor, applicationVersion.Build);
}
public static string GetBuildDate()
{
return File.GetLastWriteTime(Assembly.GetExecutingAssembly().Location).ToShortDateString();
}
public static string GetDevelopmentDetails()
{
string Result = string.Empty;
string FooterDescription = System.Configuration.ConfigurationManager.AppSettings.Get("FooterDescription");
string DataSource = string.Empty;
string Database = string.Empty;
if (!string.IsNullOrEmpty(FooterDescription))
{
string ConnectionString = ConfigurationManager.ConnectionStrings["DatabasePortlandHR1"].ConnectionString;
string[] Items = ConnectionString.Split(Convert.ToChar(";"));
foreach (string Item in Items)
{
string[] KeyValues = Item.Split(Convert.ToChar("="));
if (string.Compare(KeyValues[0], "Data Source", true) == 0)
DataSource = KeyValues[1].ToString();
if (string.Compare(KeyValues[0], "Database", true) == 0)
Database = KeyValues[1].ToString();
}
Result = string.Format("{0}<br />{1}<br />{2}", FooterDescription.ToUpper(), DataSource.ToUpper(), Database.ToUpper());
}
return Result;
}
}
#endregion I hope this helps you with your development!