Getting the Version of my C# app?

后端 未结 3 1437
失恋的感觉
失恋的感觉 2021-02-03 22:11

I am working on desktop application. I have create a setup.

Ex. My Application. Version is 1.0.0.

I want to get the current version

3条回答
  •  北海茫月
    2021-02-03 22:34

    Get the version of a specific assembly:

    private const string AssemblyName = "MyAssembly"; // Name of your assembly
    
    public Version GetVersion()
    {
        // Get all the assemblies currently loaded in the application domain.
        Assembly[] assemblies = Thread.GetDomain().GetAssemblies();
    
        for (int i = 0; i < assemblies.Length; i++)
        {
            if (string.Compare(assemblies[i].GetName().Name, AssemblyName) == 0)
            {
                return assemblies[i].GetName().Version;
            }
        }
    
        return Assembly.GetExecutingAssembly().GetName().Version; // return current version assembly or return null;
    }
    

提交回复
热议问题