26

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

4

5 回答 5

14

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

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

在 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);
            }
        }
    }
}
于 2008-09-30T08:19:36.813 回答
2

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

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

于 2019-04-11T11:06:53.437 回答
0

桌面图标可以是.application文件的快捷方式。将其安装为您的应用程序首先要做的事情之一。

于 2008-09-30T08:15:00.117 回答
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 应用程序。

于 2021-01-26T11:43:20.827 回答