我可以为ClickOnce应用程序创建桌面图标吗?
-
02-07-2019 - |
题
我在一些ClickOnce帖子中看到,ClickOnce不允许您为应用程序创建桌面图标。有没有办法解决这个问题?
解决方案
在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);
}
}
}
}
其他提示
似乎有一种方法可以在ClickOnce中在桌面上放置一个图标。
- 升级到Visual  Studio  2008 SP 1,项目属性窗口的发布部分的选项页面中的桌面上会放置一个图标复选框。
- 第二个选项是向应用程序添加代码,以便在首次运行应用程序时将快捷方式复制到桌面。请参阅博客文章 如何向ClickOnce部署应用程序添加桌面快捷方式 的 醇>
桌面图标可以是 .application
文件的快捷方式。将此安装为您的应用程序所做的第一件事。
在Visual Studio 2017和2019中,您可以执行以下操作:
转到项目属性 - >发布 - >清单并选择创建桌面快捷方式
选项不隶属于 StackOverflow