9

I'm not even sure if versioning is the right word for it, but it'll have to do. I want to start putting a 'Version x.x.xx' note on our internal apps by request of our users, so they have a rough of idea of when it gets updated (and in the future, make that a link that shows changes). It seems like using the AssemblyInfo.cs file is a good idea - it lets you automatically update the build+revision which is nice (for the .DLL of the web application).

Is this a decent approach? Then whenever I reach the major/minor version milestones for my app. I can just update those manually, correct? All of this assumes I can actually get the version information from my app. somehow, which I haven't a clue how to do either.

5 Answers 5

10

We do the same thing in our application. Although you can add the version number manually, our version info is added to the assembly as part of our automated build process (we use a customized TFS 2008 service), which I highly recommend. Here's the control we use (we just put this at the bottom of the master page):

public class BuildVersion : WebControl
{
    /// <summary>
    /// Render override
    /// </summary>
    /// <param name="writer"></param>
    protected override void Render(HtmlTextWriter writer)
    {
        writer.Write("<!--");
        writer.Write("Version: ");
        writer.Write(GetAssemblyVersion());
        writer.Write("-->");
    }

    private string GetAssemblyVersion()
    {
        try
        {
            Object[] atts = Assembly.GetAssembly(this.GetType()).GetCustomAttributes(true);
            foreach (Object o in atts)
            {
                if (o.GetType() == typeof(AssemblyVersionAttribute))
                {
                    return ((AssemblyVersionAttribute)o).Version;
                }
            }
            return String.Empty;
        }
        catch
        {
            return "Failed to load assembly";
        }
    }
}
0
3

You can use version numbers in the way you describe, just changing the numbers in the AssemblyInfo file as you build new releases but it's better when linked to a Source Control system. We use CrusieControl.NET and Web Deployment projects to set the version number but I'm sure others will have other suggestions.

Also you can get the version number from a compiled Website by using this code:

System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.ToString

If your running in Debug mode before you compile it will show 0.0.0.0 but you can check for this and display "Development" or some such to show to yourself it is running locally (not that you wouldn't know but then if you ever do see 0.0.0.0 you know something is wrong.

Hope that helps

2
  • Some parentheses errors... GetExecutingAssembly().GetName().Version.ToString();
    – Mayo
    Commented Sep 18, 2009 at 18:31
  • I've never used CruiseControl (or nAnt as Charles mentioend), so I'll have to look into these too. More tools for my belt. Thanks!
    – asple
    Commented Sep 18, 2009 at 18:35
1

It's not a bad idea. The solution to get your ASP.NET Web App DLL version is simple:

VB.NET

My.Application.Info.Version (VB.NET)

C#

Gain access to the My namespace as shown here http://www.codeproject.com/KB/cs/MyNamespace.aspx

Much easier than using tons of code.

1

We automate the versioning with subversion, ccnet and nant.

Our script parses the folder path( /Branches/1.4.5/Source...) and extracts the version number (1.4.5). After that we retrieve the current revision number from subversion and we place it in the last position of the version (i.e. 1.4.5.346). Once we have the complete version number we inject it into all the assemblies and write it to a version.txt files so it easy to determine what version is currently deployed on the web servers.

0
0

Given an Assembly a, use a.GetName().Version.ToString() to get the version in code.

GetName returns an AssemblyName.

The version returns the version as specified in your AssemblyInfo file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.