Showing ClickOnce deployment version on WPF application

后端 未结 5 963
夕颜
夕颜 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:38

    Try this:

    public static Version GetPublishedVersion()
    {
        XmlDocument xmlDoc = new XmlDocument();
        Assembly asmCurrent = System.Reflection.Assembly.GetExecutingAssembly();
        string executePath = new Uri(asmCurrent.GetName().CodeBase).LocalPath;
    
        xmlDoc.Load(executePath + ".manifest");
        string retval = string.Empty;
        if (xmlDoc.HasChildNodes)
        {
            retval = xmlDoc.ChildNodes[1].ChildNodes[0].Attributes.GetNamedItem("version").Value.ToString();
        }
        return new Version(retval);
    }
    

提交回复
热议问题