views:

2351

answers:

3

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?

A: 

The desktop icon can be a shortcut to the .application file - why not install this as one of the first things your app does?

1800 INFORMATION
+3  A: 

It seems like there is a way to place an icon on the desktop in click once.

  1. Upgrade to VS 2008 SP 1 and there will be a place icon on desktop check box in the options page of the publish section of the project properties window.See this MSDN post
  2. The second option to add code to your application that copies the shortcut to the desktop on the first run of the application. See this blog
FryHard
+8  A: 

In VS2005 ClickOnce does not have the ability to create a desktop icon, but it is now available in VS2008 SP1. In VS2005 you can use the following code to create a desktop icon for you when the application starts. 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);
                    }
              }
     }
Timo
If you copy code you should at least reference the author:http://geekswithblogs.net/murraybgordon/archive/2006/10/04/93203.aspx
cgreeno