【问题标题】:ClickOnce create new shortcuts (suffix -1, -2) after application upgradeClickOnce 在应用程序升级后创建新的快捷方式(后缀 -1、-2)
【发布时间】:2021-07-27 09:01:51
【问题描述】:

我有一个 WPF 应用程序,它通过 ClickOnce 进行部署。 ClickOnce 在每次应用程序升级后创建新的快捷方式(后缀 -1、-2)。这导致我的桌面上有多个快捷方式。

另外,如果我在 win10 中将应用固定到我的任务栏,它会在每次应用升级后将其删除,这需要重新固定应用。

我怎样才能停止这两个问题?

  1. 在桌面停止多个快捷方式
  2. 停止从任务栏中删除固定的应用程序

【问题讨论】:

    标签: clickonce shortcut


    【解决方案1】:

    在桌面停止多个快捷方式

    你可以在代码中处理这个:

    1. 首先禁用自动创建快捷方式
    2. 在首次运行时检查并创建新的快捷方式。

    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);
                }
            }
        }
    }
    

    停止从任务栏中删除固定的应用程序

    检查这个:How to pin an application to the taskbar

    【讨论】:

      猜你喜欢
      • 2012-10-29
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2010-09-19
      • 2013-05-07
      • 2020-03-24
      相关资源
      最近更新 更多