Posted by Brian Clifton
Written February 11, 2011 at 10:43
I typically update the .NET assembly for this website by hand whenever I have a new major release and I'd like to be able to get the version.
Unlike a Windows Forms application, there is no Application.ProductVersion. I Googled for answers and it looked like I needed to do this:using System.Reflection;
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
However, that causes a SecurityException to be thrown. I'm running my website at GoDaddy.com in a shared hosting environment and the permissions are limited.
Here's how I solved the problem...using System.Reflection;
Type t = typeof(*pick any class that's in the assembly you want the version of*);
AssemblyName an = new AssemblyName(Assembly.GetAssembly(t).FullName);
string version = an.Version.ToString();
Some examples that I found use Assembly.GetExecutingAssembly(), but I found that this doesn't work. It'll compile, but always returns back 0.0.0.0 as the version. That's why you'll have to use Assembly.GetAssembly() and provide a type as shown above.