我可以为ClickOnce应用程序创建桌面图标吗?
时间:2020-03-06 14:54:45 来源:igfitidea点击:
我已经阅读了一些ClickOnce帖子,其中说ClickOnce不允许我们为应用程序创建桌面图标。有没有办法解决?
解决方案
桌面图标可以是.application文件的快捷方式。将其安装为应用程序要做的第一件事。
似乎有一种方法可以在ClickOnce中将图标放置在桌面上。
- 升级到Visual Studio 2008 SP 1,将在项目属性窗口的"发布"部分的选项页中的桌面复选框上放置一个图标。
- 第二个选项是将代码添加到应用程序,该代码在应用程序的首次运行时将快捷方式复制到桌面。请参阅博客文章如何将桌面快捷方式添加到ClickOnce部署应用程序。
在VisualStudio2005中,ClickOnce不具有创建桌面图标的功能,但现在在VisualStudio2008 SP1中可用。在VisualStudio2005中,可以在应用程序启动时使用以下代码为我们创建桌面图标。
我已经在几个月的项目中使用了此代码几个月,没有任何问题。我必须说,我所有的应用程序都已在受控环境中通过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); } } } }