问题描述
简短版本
是否可以在运行时自动更新ClickOnce应用程序 ?
Is there a way to automatically update a ClickOnce application while it is running?
长版...
设置 >
我为正在开发的应用程序提供了API和控制台代理。我需要卸载一些工作,这是处理该问题的最简单,最快的方法。我是ClickOnce的新手(实际上,这是我唯一一次使用它),但对我来说似乎很完美。我已经对其进行了设置,以使应用程序在设置了不安装选项的情况下可以在线运行。
I have an API and a console agent for an application I'm developing. I needed some work offloaded and this was the easiest and quickest way to handle that. I'm new to ClickOnce (this is the only time I've ever used it, in fact), but it seems perfect for me. I've set it up so that the application runs online with the "no installation" option set.
在大规模情况下,代理会调用API询问其内容应该执行该操作,API会返回任务和所需的任何参数。
At a high scale, the agent calls the API to ask what it should do, and the API returns down a task and whatever parameters are required.
问题
由于控制台运行程序具有安静的性质,因此我试图使其尽可能少地与用户交互。但是,我现在面临着需要对其进行更新的问题。会在壁橱中的服务器上运行,所以我真的不想每次都需要重新启动应用程序时连接显示器。
Because of the "quiet' nature of my console runner, I'm trying to make it require as little user interaction as is possible. However, I'm now facing the issue of needing to update it. Ideally, it'd be running on a server in my closet, so I'd really rather not have to connect a monitor and all that every time I need to restart the app.
在运行ClickOnce应用程序时,有什么好方法吗?
Is there a good way to update a ClickOnce application while it's running?
可能的解决方案
我在搜索中没有发现与此相关的任何内容。我发现了一些谈论更新的地方,但是它们都提供了如何在更新时检查更新的示例。应用程式许可开始。
I haven't found anything relating to this in my searches. I've found a few places talking about doing updates, but they're all giving examples of how to check for updates when the application starts. That's not even relevant for me, since I'm not installing it on the client machine.
就像我说的那样,服务器将命令下推到应用程序,所以它对我来说根本不相关。对于我来说,执行执行更新的操作对我来说没有问题。我最初的想法是这样做,然后执行 Process.Start(string)
来提取 .application
文件从我的Web服务器上下载,该服务器当然具有最新版本。我可以这样做,然后停止正在运行的实例,从理论上讲这将起作用。
As I said, the server is pushing commands down to the application, so it'd be no problem for me to implement one that says "perform an update." My initial thought was to do that, then do a Process.Start(string)
to pull up the .application
file from my web server, which will of course have the latest version. I could do that, then stop the running instance, and theoretically that would work.
但这会带来签名问题。我宁愿不处理签名,尽管坦白地说我从来没有做过任何事情,所以也许它听起来并不那么糟糕。但是现在,当我从我的网站启动运行器时,它要求我单击Windows对话框以确保识别出风险。我不在乎是否必须在第一次运行时这样做,但是很显然,这否定了能够进行这样的生产中更新的好处。
But that raises issues with signing things. I'd rather not deal with signing, although admittedly I've never done anything with it so maybe it isn't as bad as it sounds. But right now, when I start the runner from my website, it requires that I click a Windows dialog to ensure that I recognize the risks. I don't care if I have to do that for the first run, but clearly that negates the benefits of being able to do an in-production update like this.
也许签名比我想象的容易?是否有一种免费的方法可以对应用程序进行免费签名,并使其具有足够的可信任性,至少在接受一次之后,我才能避免该对话框?
Maybe signing is easier than I think? Is there a good way to, for free, sign the application and have it trustworthy enough that I can avoid that dialog, at least after I've accepted it once?
我很乐意使用标准方法来执行此操作,但是由于这不是一个特别标准的问题,因此我也愿意接受非标准方法。例如,如果我可以启动另一个控制台应用程序,则停止主控制台应用程序,换出一些应用程序文件,然后启动它,这可能会起作用。但这听起来很容易失败,而且通常比我希望的复杂得多。
I'd love a standard way to do this, but since it's not a particularly standard problem I'm also open to less-than-standard ways. For instance if I could start another console app, stop the main one, swap out some application files, then start it up, that could work. But that sounds super prone to failure and just generally more complicated than I'd like for this to be.
这不一定是100%的解决方案。显然,这很不错,但是仅在大多数时间中起作用就足够了,因为这实际上是我的个人项目,而不是客户计算机上的任何事情。
It doesn't have to be a 100% solution. Obviously that would be nice, but just something that works most of the time would suffice, since this is really more a personal project of mine than anything that goes on client's computers.
推荐答案
您需要
有方法和
当有可用更新时,请使用或
When an update is available use Update() or UpdateAsync()
这是重启ClickOnce应用程序的方法。
And that is a way to restart ClickOnce applications.
using System.Diagnostics;
using System.Windows;
public class Foo
{
public void Restart()
{
Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
}
}
这篇关于重新启动和更新生产中的ClickOnce应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!