开发者

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?开发者_如何学JAVA

Thanks


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;
}


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);


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜