2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C#でWindowsフォームアプリケーションの単一EXEファイルを作成する

2
Last updated at Posted at 2026-10-04

1. はじめに

  • ビルドすると EXEファイル 以外にも dll や json が出力されるため、1つの EXEにまとめたい
    image.png

2. 開発環境

  • Visual Studio 2022
  • .NET 9.0
  • Windows Forms
  • Windows 11

3. 実行プロファイルの作成

1. プロジェクトを右クリックして「発行」を選択するimage.png

2. 「フォルダー」を選択して「次へ」をクリックする

image.png

3. 「フォルダー」を選択して「次へ」をクリックする

image.png

4. 「保存」をクリックする

image.png

4.プロジェクトファイルの編集

  • PropertyGroupにIncludeNativeLibrariesForSelfExtractプロパティを追加しTrueに設定する
  • Releaseビルドの場合に.pdbファイルを生成しないように設定するため、PropertyGroupにDebugTypeをnoneに設定する
WinFormsApp1.csproj
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net9.0-windows</TargetFramework>
        <Nullable>enable</Nullable>
        <UseWindowsForms>true</UseWindowsForms>
        <ImplicitUsings>enable</ImplicitUsings>
       
        <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+   <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
    </PropertyGroup>

+   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+       <DebugType>none</DebugType>
+   </PropertyGroup>

</Project>

5. 動作確認

  • プロジェクトを選択して発行メニューより発行する
    image.png

  • 単一EXEファイルのみ発行できた

image.png

6. 参考文献

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?