首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ClickOnce在应用程序升级后创建新的快捷方式(后缀为-1,-2)

ClickOnce在应用程序升级后创建新的快捷方式(后缀为-1,-2)
EN

Stack Overflow用户
提问于 2021-07-27 09:01:51
回答 1查看 169关注 0票数 0

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

另外,如果我将应用程序钉在win10的任务栏上,它会在每次应用程序升级后将其删除,这需要对应用程序进行修复。

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

  1. 停止桌面
  2. 中的多个快捷方式停止从任务栏

中删除固定应用程序

EN

回答 1

Stack Overflow用户

发布于 2021-08-11 07:02:33

停止桌面上的多个快捷方式

您可以在代码中处理这一问题:

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

代码语言:javascript
运行
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68541930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档