【发布时间】:2021-07-27 09:01:51
【问题描述】:
我有一个 WPF 应用程序,它通过 ClickOnce 进行部署。 ClickOnce 在每次应用程序升级后创建新的快捷方式(后缀 -1、-2)。这导致我的桌面上有多个快捷方式。
另外,如果我在 win10 中将应用固定到我的任务栏,它会在每次应用升级后将其删除,这需要重新固定应用。
我怎样才能停止这两个问题?
- 在桌面停止多个快捷方式
- 停止从任务栏中删除固定的应用程序
【问题讨论】:
我有一个 WPF 应用程序,它通过 ClickOnce 进行部署。 ClickOnce 在每次应用程序升级后创建新的快捷方式(后缀 -1、-2)。这导致我的桌面上有多个快捷方式。
另外,如果我在 win10 中将应用固定到我的任务栏,它会在每次应用升级后将其删除,这需要重新固定应用。
我怎样才能停止这两个问题?
【问题讨论】:
在桌面停止多个快捷方式
你可以在代码中处理这个:
static void CheckForShortcut()
{
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
if (ad.IsFirstRun) //first time user has run the app
{
Assembly code = Assembly.GetExecutingAssembly();
string company = string.Empty;
string description = string.Empty;
if (Attribute.IsDefined(code, typeof(AssemblyCompanyAttribute)))
{
AssemblyCompanyAttribute ascompany =
(AssemblyCompanyAttribute)Attribute.GetCustomAttribute(code,
typeof(AssemblyCompanyAttribute));
company = ascompany.Company;
}
if (Attribute.IsDefined(code, typeof(AssemblyDescriptionAttribute)))
{
AssemblyDescriptionAttribute asdescription =
(AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code,
typeof(AssemblyDescriptionAttribute));
description = asdescription.Description;
}
if (company != string.Empty && description != string.Empty)
{
string desktopPath = string.Empty;
desktopPath =
string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"\\", description, ".appref-ms");
string shortcutName = string.Empty;
shortcutName =
string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs),
"\\", company, "\\", description, ".appref-ms");
System.IO.File.Copy(shortcutName, desktopPath,true);
}
}
}
}
停止从任务栏中删除固定的应用程序
【讨论】: