none
Click Once Application - Deploy Icon and Desktop Shortcut?

    Question

  • I have created a Click Once application. This application will be installed at several of our locations. I want the installation to be as easy as possible and the end result needs to ensure that a desktop icon is created with a custom icon that has been created for the application.


    Can the Click Once application deployment add a desktop icon to the end-user computer? What steps do I need to follow in order to accomplish this?


    I would also like to have the icon designated to the programs menu item.


    Your help is appreciated,

    KJAK
    Monday, October 20, 2008 2:37 PM

Answers

  • To set the icon used by the application, you need to go to the main project and set it in the Application tab. (Then, of course, assign it to the [icon] property on all the forms.)

     

    If you are targeting .Net 3.5, and your prerequisite is .Net 3.5 SP-1, you can go to the Publish Options in the Publish tab, go to the Manifests entry, and check "Create desktop shortcut", and it will do it for you.

     

    If you are targeting a different version of the framework, here's how to programmatically create a desktop shortcut:

     

    /// <summary>
    /// This will create a Application Reference file on the users desktop
    /// if they do not already have one when the program is loaded.
    /// Check for them running the deployed version before doing this,
    /// so it doesn't kick it when you're running it from Visual Studio.
    /// </summary
    static void CheckForShortcut()
    {
        if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
        {
            ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
            if (ad.IsFirstRun)  //first time user has run the app
                {
                    Assembly code = Assembly.GetExecutingAssembly();
                    string company = string.Empty;
                    string description = string.Empty;
                    if (Attribute.IsDefined(code, typeof(AssemblyCompanyAttribute)))
                    {
                    AssemblyCompanyAttribute ascompany =
                      (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(code,
                      typeof(AssemblyCompanyAttribute));
                   company = ascompany.Company;
                }
                if (Attribute.IsDefined(code, typeof(AssemblyDescriptionAttribute)))
                {
                    AssemblyDescriptionAttribute asdescription =
                      (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code,
                        typeof(AssemblyDescriptionAttribute));
                    description = asdescription.Description;
                }
                if (company != string.Empty && description != string.Empty)
                {
                    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);
                }
            }
        }
    }

    RobinS.

    GoldMail.com

     

    Monday, October 20, 2008 8:54 PM
    Moderator

All replies

  • To set the icon used by the application, you need to go to the main project and set it in the Application tab. (Then, of course, assign it to the [icon] property on all the forms.)

     

    If you are targeting .Net 3.5, and your prerequisite is .Net 3.5 SP-1, you can go to the Publish Options in the Publish tab, go to the Manifests entry, and check "Create desktop shortcut", and it will do it for you.

     

    If you are targeting a different version of the framework, here's how to programmatically create a desktop shortcut:

     

    /// <summary>
    /// This will create a Application Reference file on the users desktop
    /// if they do not already have one when the program is loaded.
    /// Check for them running the deployed version before doing this,
    /// so it doesn't kick it when you're running it from Visual Studio.
    /// </summary
    static void CheckForShortcut()
    {
        if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
        {
            ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
            if (ad.IsFirstRun)  //first time user has run the app
                {
                    Assembly code = Assembly.GetExecutingAssembly();
                    string company = string.Empty;
                    string description = string.Empty;
                    if (Attribute.IsDefined(code, typeof(AssemblyCompanyAttribute)))
                    {
                    AssemblyCompanyAttribute ascompany =
                      (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(code,
                      typeof(AssemblyCompanyAttribute));
                   company = ascompany.Company;
                }
                if (Attribute.IsDefined(code, typeof(AssemblyDescriptionAttribute)))
                {
                    AssemblyDescriptionAttribute asdescription =
                      (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code,
                        typeof(AssemblyDescriptionAttribute));
                    description = asdescription.Description;
                }
                if (company != string.Empty && description != string.Empty)
                {
                    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);
                }
            }
        }
    }

    RobinS.

    GoldMail.com

     

    Monday, October 20, 2008 8:54 PM
    Moderator
  • 1) What about when you uninstall the Click Once application?

    2) I find when you uninstall the Click Once application it deletes it's container folder, regardless if it has other application which reside in it too.
    Wednesday, April 29, 2009 12:32 PM
  • What do you mean by "it deletes its container folder" ? Do you mean in the ClickOnce cache?

    RobinS.

    GoldMail.com


    Visit my ClickOnce blog!
    Thursday, April 30, 2009 5:35 PM
    Moderator
  • If you have multiple ClickOnce apps which go into the same folder in All Programs->YourCompany then when issuing update for / or uninstalling one of the ClickOnce apps the above folder is emptied out and shortcuts to other apps are deleted.

    Lets say I had something like the following:

    All Programs
        - My Company
             - App1
             - Suite1
                - App2
                - App3
             - Suite2
                - App4

    When I issue update for App1, Suite1 and Suite2 folders would be deleted. :( And will get back there after I issue updates for App2, App3 and App4, which makes it a very painful experience for users.

    Thursday, December 10, 2009 6:15 PM
  • I have not found this to be true, but I am not using the Suite field with my deployment. Just out of curiosity, can you try it w/o using the Suite field and see if it works differently?

    RobinDotNet
    Click here to visit my ClickOnce blog!
    Microsoft MVP, Client App Dev
    Friday, December 11, 2009 8:37 AM
    Moderator
  • Hi,

    How do I shell from my c# project to a previous installed Clickone/Application Refference ????
    I don't want a ClickOne Shortcut - Just a .Bat file (or short cut) I can call to from my new C#2010 program.
    Thanks



    ADH
    Sunday, February 20, 2011 11:09 AM
  • I already answered this question in your original thread.

    RobinDotNet


    Click here to visit my ClickOnce blog!
    Microsoft MVP, Client App Dev
    Wednesday, February 23, 2011 9:34 AM
    Moderator
  • Hi,

    I do have the similar need.

    Can I used your code for my VB.net app.

    If so, where should I place the code.

    Thank you.


    TS Lim

    Saturday, August 18, 2012 5:51 AM
  • I think I already answered this for you in another thread.  Please don't multi-post.

    Here's the article you're looking for.

    http://robindotnet.wordpress.com/2009/07/19/clickonce-desktop-shortcut-using-vb/

    Robin


    Click here to visit my ClickOnce blog!
    Microsoft MVP, Client App Dev

    Tuesday, August 21, 2012 7:15 AM
    Moderator
  • Sorry for the multi-post and thanks for the answer.

    TS Lim

    Thursday, August 23, 2012 9:32 AM