26

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

4

5 に答える 5

14

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

  1. Visual Studio 2008 SP 1にアップグレードすると、プロジェクトのプロパティウィンドウの公開セクションのオプションページにあるデスクトップのチェックボックスにアイコンが配置されます。
  2. 2番目のオプションは、アプリケーションの最初の実行時にショートカットをデスクトップにコピーするコードをアプリケーションに追加することです。ClickOnce配置アプリケーションにデスクトップショートカットを追加する方法に関するブログ投稿を参照してください。
于 2008-09-30T08:18:16.300 に答える
12

Visual Studio 2005では、ClickOnceにデスクトップアイコンを作成する機能はありませんが、Visual Studio2008SP1で使用できるようになりました。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);
            }
        }
    }
}
于 2008-09-30T08:19:36.813 に答える
0

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

于 2008-09-30T08:15:00.117 に答える