ClickOnceアプリケーションのデスクトップアイコンを作成できますか?

StackOverflow https://stackoverflow.com/questions/152188

  •  02-07-2019
  •  | 
  •  

質問

ClickOnceでアプリケーションのデスクトップアイコンを作成することは許可されていないというClickOnceの投稿をいくつか読みました。これを回避する方法はありますか?

役に立ちましたか?

解決

Visual  Studio  2005では、 ClickOnce にデスクトップアイコンを作成する機能がありません、ただしVisual  Studio  2008 SP1で利用できるようになりました。 Visual  Studio  2005では、次のコードを使用して、アプリケーションの起動時にデスクトップアイコンを作成できます。

私はこのコードを数か月間、問題なくいくつかのプロジェクトで使用しました。すべてのアプリケーションは、制御された環境のイントラネット上に展開されていると言わなければなりません。また、アプリケーションをアンインストールしてもアイコンは削除されません。このコードは、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);
            }
        }
    }
}

他のヒント

ClickOnceのデスクトップにアイコンを配置する方法があるようです。

  1. Visual  Studio  2008 SP 1にアップグレードすると、プロジェクトプロパティウィンドウの公開セクションのオプションページにデスクトップのチェックボックスにアイコンが配置されます。
  2. 2番目のオプションは、アプリケーションの最初の実行時にデスクトップにショートカットをコピーするコードをアプリケーションに追加することです。ブログ投稿 ClickOnceデプロイメントアプリケーションにデスクトップショートカットを追加する方法

デスクトップアイコンは、 .application ファイルへのショートカットにすることができます。これをアプリケーションが最初に行うことの1つとしてインストールします。

Visual Studio 2017および2019では、次のことができます:

プロジェクトのプロパティに移動->公開->マニフェストを選択し、[デスクトップショートカットを作成]オプションを選択します

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top