简体   繁体   English

ClickOnce:“未设置应用程序身份”

[英]ClickOnce: “Application identity is not set”

I have a pretty old Windows Forms application for which I'm currently trying to build a ClickOnce installer. 我有一个很旧的Windows窗体应用程序,目前正在尝试为其构建ClickOnce安装程序。

Everything is fine except that any attempt to access ApplicationDeployment.CurrentDeployment from within the application results in: 一切都很好,除了从应用程序内部访问ApplicationDeployment.CurrentDeployment的任何尝试都会导致:

Application identity is not set. 未设置应用程序身份。

I found a lot of posts of this kind on web and particularly here on Stack Overflow, but people run their application under a debugger or simply not network-deployed local versions. 我在Web上发现了很多此类帖子,尤其是在Stack Overflow上,但是人们在调试器上运行他们的应用程序,或者根本不在网络上部署本地版本。

I emphasize that in my case the application is network-deployed (available offline). 我强调在我的情况下,该应用程序是网络部署的(可脱机使用)。 I'm running it by clicking the desktop icon created by ClickOnce installer. 我通过单击ClickOnce安装程序创建的桌面图标来运行它。 Update works fine (tried to publish an update to make sure it works). 更新工作正常(尝试发布更新以确保它可以运行)。

Nevertheless, ApplicationDeployment.CurrentDeployment is not accessible. 但是,无法访问ApplicationDeployment.CurrentDeployment。

What I'm doing wrong? 我做错了什么?

In fact, I'm only trying to read the application's version as it appears in the "Programs and Features" applet. 实际上,我只是试图读取应用程序的版本,该版本显示在“程序和功能”小程序中。 Is there a way to read this information without using of ClickOnce API, for example, directly from the registry (I understand that it is not nice). 有没有一种方法可以不使用ClickOnce API来读取此信息,例如,直接从注册表中读取该信息(我知道这不好)。

The code is very simple: 代码很简单:

[STAThread]
static void Main(string[] argv)
{
System.Windows.Forms.MessageBox.Show(ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString()); // Crash here
DoSomethingUseful();
}

I have done this using a property and bound its value in XAML directly. 我已经使用属性完成此操作,并直接在XAML中绑定其值。 I am using WPF, but I hope this helps. 我正在使用WPF,但是希望对您有所帮助。

private string _verSion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
public string verion
{
    get
    {
        return _verSion;
    }
    set
    {
        _verSion = value;
        OnPropertyChanged(() => verion);
    }
}

I have not done this using a message box. 我尚未使用消息框完成此操作。 You can try the same. 您可以尝试相同的方法。 Open a window "About Us" or something. 打开一个窗口“关于我们”或其他内容。 Take a string and bind it to this property. 取一个字符串并将其绑定到此属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM