Can I create a desktop icon for a ClickOnce application?
Asked Answered
A

6

26

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?

Antineutrino answered 30/9, 2008 at 8:12 Comment(0)
R
12

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.

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);
            }
        }
    }
}
Rolf answered 30/9, 2008 at 8:19 Comment(2)
If you copy code you should at least reference the author: geekswithblogs.net/murraybgordon/archive/2006/10/04/93203.aspxNoseband
Note: This requires: using System.Deployment.Application; using System.Reflection; I had to also add a reference to System.Deployment. Thanks to Jerry Odom's comment at geekswithblogs.net/murraybgordon/archive/2006/10/04/93203.aspx for this info.Raptorial
R
13

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

  1. Upgrade to Visual Studio 2008 SP 1, and there will be a placed an icon on the desktop check box in the options page of the publish section of the project properties window.
  2. The second option is to add code to your application that copies the shortcut to the desktop on the first run of the application. See the blog post How to add Desktop Shortcut to ClickOnce Deployment Application.
Rianna answered 30/9, 2008 at 8:18 Comment(3)
Perfect. The same setting is in VS2010 if anyone else is wondering.Multiform
VS2015 as well: Project Properties > Publish > Options > Manifests > Create desktop shortcutSalisbury
The link is dead :(Magnetize
R
12

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.

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);
            }
        }
    }
}
Rolf answered 30/9, 2008 at 8:19 Comment(2)
If you copy code you should at least reference the author: geekswithblogs.net/murraybgordon/archive/2006/10/04/93203.aspxNoseband
Note: This requires: using System.Deployment.Application; using System.Reflection; I had to also add a reference to System.Deployment. Thanks to Jerry Odom's comment at geekswithblogs.net/murraybgordon/archive/2006/10/04/93203.aspx for this info.Raptorial
H
5

In Visual Studio 2017 and 2019 you can do the following:

Go to Project Properties -> Publish -> Manifests and select the option Create desktop shortcut

Horney answered 11/4, 2019 at 11:6 Comment(1)
Did not know this was an option until one day it stopped creating shortcuts.Delamination
G
0

The desktop icon can be a shortcut to the .application file. Install this as one of the first things your application does.

Gause answered 30/9, 2008 at 8:15 Comment(0)
J
0

If you would like to user powershell you can create shortcut to .bat file:

@ECHO OFF
PowerShell -ExecutionPolicy Unrestricted .\script.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
EXIT /B %errorlevel%

which silently run script.ps1:

$app = "http://your.site/YourApp/YourApp.application";
[Diagnostics.Process]::Start("rundll32.exe", "dfshim.dll,ShOpenVerbApplication " + $app);

which open your ClickOnce app.

Jeffrey answered 26/1, 2021 at 11:43 Comment(0)
M
0

If some one looks for setting options using Visual studio 2022,

  • After selecting "Clickonce", select "next" on publish window.

  • Keep selecting "next" till you reach to "settings".

  • Now select "options" link which opens "Publish Options" window.

  • Select "Manifest" on "Publish Options" window.

  • Then you will observe a check box saying "Create desktop shortcut".
    Select it.

Marcille answered 23/5, 2023 at 0:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.