7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

.NET9のWPFアプリを爆速で作る インストーラー編

Last updated at Posted at 2025-03-01

概要

WindowsアプリのインストーラーをMicrosoft Visual Studio Installer Projects 2022で作ります。
以下の利点があります。

  • リポジトリにインストーラーのソースコードを含めることができる
  • ランタイムの配布が容易になる

サンプルコード

方法

拡張機能の追加

Visual Studio 2022のメニューバー > 拡張機能 > 拡張機能の管理 より、
Microsoft Visual Studio Installer Projects 2022
をインストールします。
スクリーンショット 2025-02-26 225252.png

Setup Projectの追加

Setup Projectをソリューションに追加します。
スクリーンショット 2025-02-27 215834.png

インストール対象のアプリケーション指定

プロジェクトを右クリックし、View > ファイルシステム を選択します。
Application Folder を右クリックし、Add > プロジェクト出力 を選択します。
image.png

PublishItemsOutputGroup を選択します。
スクリーンショット 2025-02-27 221909.png

デスクトップショートカットとスタートメニューに表示するアイコンもApplication Folderに追加しておきます。
Application Folder を右クリックし、Add > ファイル を選択します。
image.png

リポジトリに含まれるicoファイルを選択し、Application Folderに追加します。
image.png

デスクトップショートカットの作成

User's Desktop の右側部分を右クリックし、新しいショートカットの作成を選択します。
image.png

Application FolderのPublishItemsOutputGroupを選択します。
image.png

プロパティウィンドウより、Nameを変更し、Iconを指定します。
image.png

スタートメニューの作成

デスクトップショートカットと同じように、新しいショートカットを作成します。
スタートメニューをフォルダ階層化させたい場合は、User's Programs Menuを右クリックし、Add > Folder でフォルダを作成します。
image.png

あとは同じ要領でショートカットを作成、Nameを変更、Iconの指定をします。
image.png

ランタイムの配布

プロジェクトを右クリックし、プロパティ > Prerequisites より必須コンポーネントを選択します。
サンプルアプリは .NET9のWPFアプリ(x64)なので、.NET デスクトップ ランタイム 9.0.2 (x64)を選択します。
image.png

インストーラーのUI設定

プロジェクトを右クリックし、View > ユーザーインターフェース を選択します。
ダイアログの順番を入れ替えたり、プリセットされたダイアログを追加できます。
今回はStart時にライセンス条項を加えます。

Startを右クリックし、ダイアログの追加 を選択します。
image.png

ライセンス条項を選択します。
image.png

「ようこそ」と「インストールフォルダ―」の間に持っていきます。
image.png

「ライセンス条項」を右クリックし、プロパティウィンドウを選択します。
LicenseFileを選択します。リッチテキスト形式のみサポートしているようですので、Iconの追加と同じ手順で設定します。
image.png

「Administrative Install」も同様にします。
image.png

インストーラーのプロパティ設定

プロジェクトを選んだ状態で、メニューバー > 表示 > プロパティウィンドウ より、各種プロパティを設定できます
スクリーンショット 2025-02-27 221052.png

インストーラーのビルド

プロジェクトをビルドすることで、setup.exe*.msiが生成されます。
この2つのファイルを配布し、setup.exeを起動することでインストーラーが起動します。

おわりに

今回紹介したもの以外にも、インストール時に値をレジストリに書き込んだり、カスタムアクションを追加したりできます。
また、GitHub Actionのワークフロー等でCI/CDを容易に実現でき、開発コストの低減にもつながるかもしれません。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?