Showing ClickOnce deployment version on WPF application

后端 未结 5 962
夕颜
夕颜 2021-02-13 18:00

I\'m deploying now a WPF c# project and want to put the clickonce version (rather than the assembly or product version) on the screen title. I used to do it in

5条回答
  •  深忆病人
    2021-02-13 18:14

    using System;
    using System.Deployment.Application;
    
    namespace Utils
    {
        public class ClickOnce
        {
            public static Version GetPublishedVersion()
            {
                return ApplicationDeployment.IsNetworkDeployed 
                    ? ApplicationDeployment.CurrentDeployment.CurrentVersion 
                    : System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }
    }
    

    If you get an error about System.Deployment.Application, then Solution > Project > References > Add Reference > Assemblies > Framework > System.Deployment.

    Do not parse the assembly XML for this information; you're relying on undocumented behaviour which simply happens to work 'for now'.

提交回复
热议问题