0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ビルド構成ごとに設定を切り替える

Last updated at Posted at 2025-08-09

C#でMVCモデルのWebアプリケーションを新規作成しました。

作成したプロジェクトにビルド構成を追加しようと思います。

デフォルトの設定

ビルド構成

Visual Studioで新規プロジェクトを作成すると「Debug」と「Release」が用意されています。
image.png

「Debug」と「Release」のデフォルト設定は以下の通りです。

Debug

 

Release

 

コンフィグファイル

今回はWebプロジェクトを作成したので「Web.config」になります。
こちらもデフォルトで「Web.Debug.config」と「Web.Release.config」が用意されています。
image.png

以下のように設定することで、ビルド構成ごとに切り替わるようになります。

Web.config
<appSettings>
    <add key="BuildComposition" value="デフォルト値"/>
</appSettings>
Web.Debug.config
<appSettings>
    <add key="BuildComposition" value="デバッグ構成" xdt:Locator="Match(key)" xdt:Transform="Replace"/>
</appSettings>
Web.Release.config
<appSettings>
    <add key="BuildComposition" value="リリース構成" xdt:Locator="Match(key)" xdt:Transform="Replace"/>
</appSettings>

例えば、ビルド構成:Debugでビルドを行うと「Web.config」は以下のようになります。

Web.config
<appSettings>
    <add key="BuildComposition" value="デバッグ構成"/>
</appSettings>

設定を増やす

ビルド構成

「構成マネージャー」ダイアログを表示します。

image.png

ビルド構成を新規作成します。
image.png
image.png

名前を入力して、OKをクリックします。
「設定のコピー元」は既存のビルド構成を指定すると設定をコピーします。
image.png

追加されました。
image.png

コンフィグファイル

ファイル名を「Web.[ビルド構成].config」として、「Web.config」と同じフォルダにWeb構成ファイルを追加します。

image.png

追加されました。
image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?