问题描述
我有一个的ClickOnce部署的应用程序,我目前使用这种检测第一次新的部署正在运行:
如果(ApplicationDeployment.IsNetworkDeployed
&功放;&安培; ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
//显示发行说明,以便用户知道有什么新
}
这似乎按预期工作的ClickOnce进行自动更新之后。
但是,当用户进入publish.htm在安装现场,并手动安装更新的版本不会在所有的工作。有没有一种方法来检测的两个的这些条件下可靠?
编辑:我试图解释的情况:有时用户听到更新已经发布,手动去,而不是启动应用程序,以publish.htm以获得新版本,让ClickOnce的处理升级。将ClickOnce,这显然是无法区分首次安装。是真的吗?
解决方案code :我结束了以下关键部分创建一个ClickOnce的辅助类:
公共静态布尔在isfirstRun
{
得到
{
如果(!IsNetworkDeployed)
返回false; //不适用==布尔默认值
如果(!File.Exists(VersionFileName))
返回true;
(!GetLastRunVersion()= Version.ToString())回报;
}
}
公共静态无效StoreCurrentVersion()
{
File.WriteAllText(VersionFileName,Version.ToString());
}
公共静态字符串GetLastRunVersion()
{
使用(VAR流= File.OpenText(VersionFileName))
{
返回stream.ReadToEnd();
}
}
公共静态字符串VersionFileName
{
得到
{
StringBuilder的文件名=新的StringBuilder(Files.LocalFilesPath);
如果(!filename.ToString()。的endsWith(@\))
filename.Append(@\);
filename.Append(@versioninfo.dat);
返回filename.ToString();
}
}
包含在你的ClickOnce一个额外的文件安装称为justInstalled.txt(或东西)。 Chedk该文件时,应用程序启动。如果你发现它删除它,并运行任何code为第一个是部署运行。该文件将留失踪,直到下一个部署/升级。
I have a ClickOnce-deployed application and I'm currently using this to detect the first time a new deployment is being run:
if (ApplicationDeployment.IsNetworkDeployed
&& ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
// Display release notes so user knows what's new
}
It seems to works as expected after ClickOnce performs an automatic update.
But it doesn't work at all when the user goes to publish.htm on the install site and installs a newer version manually. Is there a way to detect both of these conditions reliably?
Edit: The situation I'm trying to account for: sometimes users hear that an update has been released and manually go to publish.htm to get the new version, instead of launching the application and letting ClickOnce handle the upgrade. To ClickOnce, this is apparently indistinguishable from a first-time install. Is that true?
Solution Code: I ended up creating a ClickOnce helper class with the following key section:
public static bool IsFirstRun
{
get
{
if (!IsNetworkDeployed)
return false; // not applicable == bool default value
if (!File.Exists(VersionFileName))
return true;
return (GetLastRunVersion() != Version.ToString());
}
}
public static void StoreCurrentVersion()
{
File.WriteAllText(VersionFileName, Version.ToString());
}
public static string GetLastRunVersion()
{
using (var stream = File.OpenText(VersionFileName))
{
return stream.ReadToEnd();
}
}
public static string VersionFileName
{
get
{
StringBuilder filename = new StringBuilder(Files.LocalFilesPath);
if (!filename.ToString().EndsWith(@"\"))
filename.Append(@"\");
filename.Append(@"versioninfo.dat");
return filename.ToString();
}
}
Include an extra file in your ClickOnce install called justInstalled.txt (or something). Chedk for that file when the app starts. If you find it delete it and run any code for your first run of that deployment. The file will stay missing until the next deployment/upgrade.
这篇关于我如何在第一时间检测一个的ClickOnce部署的应用程序已经运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!