29

I have a ASP.Net (.net 3.5/c#) and I want to display a version number / build number and date. What is the best way in controling this and is it possible to auto incriment the numbers on build?

What is the standard for version numbers & build number?

Im using VS 2008 how would I get the data and assign to a string value so I can show in the footer of the webpage?

2 Answers 2

39

If you're using a Web Application Project - you could do it like this...

Assembly web = Assembly.Load("App_Code");
AssemblyName webName = web.GetName();

string myVersion = webName.Version.ToString();

If you're using a Web Site project - nearly the same...

Assembly web = Assembly.GetExecutingAssembly();
AssemblyName webName = web.GetName();

string myVersion = webName.Version.ToString();
Sign up to request clarification or add additional context in comments.

2 Comments

I'm trying to do this in a razor view (I know i shouldn't but its a shared layout) and it can't see the Assembly...
@Worthy7, for a Razor view, you can set the Version in an Application variable in Application_Start() event (global.asax) like this: Application["Version"] = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();. Then retrieve it in the Razor view like this: <p>version @Context.Application["Version"].ToString()</p>
26

You can set the first two parts of the version number, and leave a wildcard for the compiler to autocomplete the last two parts, by editing the GlobalAssemblyInfo.cs like so:

[assembly:AssemblyFileVersion("1.0.*")]

It autocompletes the last two parts with a number of days since 1st Jan 2000, and the number of seconds since midnight. This may help with the second part of your query to display the date/time the version was built.

2 Comments

cool! then you can get the version: System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
the last part of the auto-completed version (the default revision number) is the number of seconds since midnight local time (without taking into account time zone adjustments for daylight saving time), divided by 2. Taken from here msdn.microsoft.com/en-us/library/…

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.