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

问题描述 投票:24回答:4

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

.net clickonce smartclient
4个回答
14
投票

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

13
投票

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

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

0
投票

桌面图标可以是.application文件的快捷方式。将此安装为您的应用程序所做的第一件事。


0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.