1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

appsettings.jsonをReleaseやDebugで切り替える

Posted at

AWSのElastic BeanstalkにASP.NET Core アプリケーションをデプロイする際、appsettings.jsonの切り替えが意外にも困ったのでまとめ。

appsettings.jsonとappsettings.Development.json、その他appsettings.xxxx.jsonなど「実行環境」の選択でappsettingsを切り替えることは簡単だが、ReleaseやDebugなど「ビルド構成」で切り替える機能は.NET Coreのアプリにはない。
いろんな方法があると思うが、csprojにmsbuildのコピーコマンドを手で追記することで、シンプルにビルド後にビルド後のディレクトリ内でappsettings.jsonをappsettings.xxx.jsonで上書きすることができた。

sample.csproj
  <Target Name="CopyStaging" AfterTargets="Build">
    <Copy SourceFiles="$(TargetDir)\settings\appsettings.$(Configuration).json" DestinationFiles="$(TargetDir)\appsettings.json" SkipUnchangedFiles="false" />
  </Target>
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?