我有一个WPF应用程序,它通过ClickOnce进行部署。ClickOnce在每次应用程序升级后创建新的快捷方式(后缀为-1,-2)。这将导致桌面上的多个快捷方式。
另外,如果我将应用程序钉在win10的任务栏上,它会在每次应用程序升级后将其删除,这需要对应用程序进行修复。
我怎样才能阻止这两个问题?
中删除固定应用程序
发布于 2021-08-11 07:02:33
停止桌面上的多个快捷方式
您可以在代码中处理这一问题:
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),