我可以为ClickOnce应用程序创建桌面图标吗?

Vel*_*uis 24 .net clickonce smartclient

我在一些ClickOnce帖子中看到,ClickOnce不允许您为应用程序创建桌面图标.有没有办法解决?

Fry*_*ard 13

似乎有一种方法可以在ClickOnce桌面上放置一个图标.

  1. 升级到Visual Studio 2008 SP 1,项目属性窗口的发布部分的选项页面中的桌面上将放置一个图标复选框.
  2. 第二个选项是向应用程序添加代码,以便在第一次运行应用程序时将快捷方式复制到桌面.请参阅博客文章如何将桌面快捷方式添加到ClickOnce部署应用程序.

  • 完善.如果其他人想知道,VS2010中的设置相同. (3认同)
  • VS2015:项目属性>发布>选项>清单>创建桌面快捷方式 (2认同)

Tim*_*imo 13

在Visual Studio 2005中,ClickOnce无法创建桌面图标,但现在可以在Visual Studio 2008 SP1中使用.在Visual Studio 2005中,您可以使用以下代码在应用程序启动时为您创建桌面图标.

我已经在几个项目中使用了这个代码几个月了,没有任何问题.我必须说我的所有应用程序都已在受控环境中通过Intranet部署.此外,卸载应用程序时不会删除该图标.此代码创建ClickOnce创建的开始菜单上快捷方式的快捷方式.

private void CreateDesktopIcon()
{
    ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

        if (ad.IsFirstRun)
        {
            Assembly assembly = Assembly.GetEntryAssembly();
            string company = string.Empty;
            string description = string.Empty;

            if (Attribute.IsDefined(assembly, typeof(AssemblyCompanyAttribute)))
            {
                AssemblyCompanyAttribute ascompany =
                  (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(
                    assembly, typeof(AssemblyCompanyAttribute));

                company = ascompany.Company;
            }
            if (Attribute.IsDefined(assembly, typeof(AssemblyDescriptionAttribute)))
            {
                AssemblyDescriptionAttribute asdescription =
                  (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
                    assembly, typeof(AssemblyDescriptionAttribute));

                description = asdescription.Description;
            }
            if (!string.IsNullOrEmpty(company))
            {
                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);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 如果您复制代码,至少应该参考作者:http://geekswithblogs.net/murraybgordon/archive/2006/10/04/93203.aspx (29认同)

小智 5

在 Visual Studio 2017 和 2019 中,您可以执行以下操作:

转到项目属性 -> 发布 -> 清单并选择选项创建桌面快捷方式