问题描述
我看过一些ClickOnce的帖子说的ClickOnce不允许您创建你应用程序的桌面图标。有没有解决这个办法吗?
I have read in some of the ClickOnce posts that ClickOnce does not allow you to create a desktop icon for you application. Is there any way around this?
推荐答案
在视觉 &工作室NBSP; 2005年,的ClickOnce 不必创建一个桌面图标的功能,但它现在可以在Visual &工作室NBSP; 2008 SP1。在Visual &工作室NBSP; 2005年,您可以使用下面的code创建一个桌面图标为你应用程序启动时
In Visual Studio 2005, ClickOnce does not have the ability to create a desktop icon, but it is now available in Visual Studio 2008 SP1. In Visual Studio 2005, you can use the following code to create a desktop icon for you when the application starts.
我已经使用这个code在几个项目的一两个月,现在没有任何问题。我必须说,我所有的应用程序已经部署了在受控的环境内联网。此外,当该应用程序被卸载的图标不会被删除。这code创建到的ClickOnce创建开始菜单上的快捷方式的快捷方式。
I have used this code over several projects for a couple of months now without any problem. I must say that all my applications have been deployed over an intranet in a controlled environment. Also, the icon is not removed when the application is uninstalled. This code creates a shortcut to the shortcut on the start menu that ClickOnce creates.
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应用程序桌面图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!