Gali
Gali

Reputation: 14973

How can I show the the build version and if its running on 64 or 32 bits in my program?

How can I show in my program if its running on 64 or 32 bit? (i.e. If i compiled it on 64 or 32 bit)

Also how can I show the build version?

Thanks

Upvotes: 2

Views: 643

Answers (4)

Vagaus
Vagaus

Reputation: 4215

If you are targeting .Net 4.0 you can use Is64BitProcess and Is64BitOperatingSystem.

Upvotes: 1

Paul Sasik
Paul Sasik

Reputation: 81527

For 32/64 bit:

bool x64;
unsafe { x64 = sizeof(System.IntPtr) == 8; }
if (x64)
    Console.WriteLine("64 bits");
else
    Console.WriteLine("32 bits");

Your build numbers can be incremented in your project's Properties\AssemblyInfo.cs file.

And this snippet to get your assembly's version at runtime:

Console.WriteLine(
    System.Diagnostics.FileVersionInfo.GetVersionInfo(
        Assembly.GetExecutingAssembly().Location).FileVersion);

Upvotes: 2

Marc Gravell
Marc Gravell

Reputation: 1063884

For the version:

 var ver = typeof(Program).Assembly.GetName().Version;

(where Program can be replaced with any type from the assembly you are interested in)

For the architecture:

bool x64 = IntPtr.Size == 8;

If you want the ClickOnce deployment version, that is obtainable - but separately (and needs a reference to System.Deployment.dll):

if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
    var ver = System.Deployment.Application.ApplicationDeployment
           .CurrentDeployment.CurrentVersion;
}

Upvotes: 4

Beth Lang
Beth Lang

Reputation: 1905

Take a look at this microsoft documentation it gives you more detail http://msdn.microsoft.com/en-us/library/system.version.build.aspx

System.Version.Build has properties that give you all the build numbers.

Upvotes: 1

Related Questions