在WPF应用程序上显示ClickOnce部署版本

Iga*_*gal 13 c# deployment wpf clickonce

我正在部署一个WPF c#项目,并希望将clickonce版本(而不是assymbly或产品版本)放在屏幕标题上.我曾经在Win表单应用程序中使用以下方式执行此操作.但似乎它不是WPF应用程序中的方式.我在Google上搜索没找到任何东西.请帮忙.

    if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
    {
        ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
        lblVer.Text = "V" + ad.CurrentVersion.ToString();
    }
    else
        lblVer.Text = "V" + Application.ProductVersion.ToString();
Run Code Online (Sandbox Code Playgroud)

Eng*_*dıç 24

试试这个:

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);
}
Run Code Online (Sandbox Code Playgroud)


Jos*_*osh 6

你得到什么错误?Windows Forms和WPF之间的ClickOnce API没有区别.它不依赖于任何UI框架.

你还记得添加对System.Deployment.dll的引用吗?


Iga*_*gal 3

好的,我发现问题了。我必须添加对这的引用,System.Deployment 这就是我无法使用它的原因。这个dll也适用于winforms。