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

26

我在一些ClickOnce的文章中读到,ClickOnce不允许为应用程序创建桌面图标。是否有任何解决方法?

6个回答

13

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

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

3
好的。如果其他人也想知道,相同的设置在VS2010中也可以找到。 - dkarzon
2
在VS2015中:项目属性 > 发布 > 选项 > 清单 > 创建桌面快捷方式。 - kdbanman
链接已失效 :( - jumbo

12
在 Visual Studio 2005 中,ClickOnce 没有创建桌面图标的功能,但在 Visual Studio 2008 SP1 中已经可用。在 Visual Studio 2005 中,您可以使用以下代码,在应用程序启动时为您创建桌面图标。
我已经在几个项目中使用了这段代码,几个月来没有任何问题。我必须说,所有我的应用程序都在受控环境下通过内部网络部署。此外,卸载应用程序时不会删除图标。此代码创建了一个指向 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);
            }
        }
    }
}

33
如果你复制代码,至少应该引用作者:http://geekswithblogs.net/murraybgordon/archive/2006/10/04/93203.aspx - cgreeno
注意:这需要使用System.Deployment.Application;和System.Reflection;。我还必须添加对System.Deployment的引用。感谢Jerry Odom在http://geekswithblogs.net/murraybgordon/archive/2006/10/04/93203.aspx上的评论提供了这些信息。 - Jeff

5
在Visual Studio 2017和2019中,您可以执行以下操作: 前往项目属性-> 发布 -> 清单,并选择选项创建桌面快捷方式

直到有一天它停止创建快捷方式,我才意识到这是一个选项。 - gbarry

0
桌面图标可以是对.application文件的快捷方式。将其作为您的应用程序最早执行的一项操作来安装。

0

如果您想使用PowerShell,可以创建到.bat文件的快捷方式:

@ECHO OFF
PowerShell -ExecutionPolicy Unrestricted .\script.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
EXIT /B %errorlevel%

静默运行 script.ps1 的代码:

$app = "http://your.site/YourApp/YourApp.application";
[Diagnostics.Process]::Start("rundll32.exe", "dfshim.dll,ShOpenVerbApplication " + $app);

打开你的 ClickOnce 应用程序。


0

如果有人想使用Visual Studio 2022进行设置选项,

  • 在选择“Clickonce”后,在发布窗口上选择“下一步”。

  • 一直选择“下一步”,直到到达“设置”。

  • 现在选择“选项”链接,打开“发布选项”窗口。

  • 在“发布选项”窗口上选择“清单”。

  • 然后您会看到一个复选框,上面写着“创建桌面快捷方式”。
    选择它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接