LoginSignup
15
20

More than 5 years have passed since last update.

C#の構成ファイルまとめ

Posted at

ややっこしいのでメモ。

*.cscfg

WebRole,WorkerRoleプロジェクトを作成するとできる。
Azure WebSitesがあるので今後はあまり使われなくなるのかも。

環境ごとの設定

環境ごと(Production,Stagingなど)の設定ができる。
ex)ServiceConfiguration.Production.cscfg

反映方法

パッケージの再作成が不要。また、Azure管理ポータルから直接変更ができる。

app.config/web.configの<appSettings>

環境ごとの設定

環境ごと(Production,Stagingなど)の設定ができる。
ex) web.Debug.config

反映方法

パッケージの再作成が必要。

app.config/web.configの<applicationSettings>

データの型指定ができる

環境ごとの設定

できない。app.Debug.configのように作成しても読み込むのは、app.config(Settings.settings)に記述されている値

反映方法

パッケージの再作成が必要。

Settings.settings

プロジェクトを右クリックして「プロパティ」 -> 「設定」で表示される。

これは、

  • スコープをアプリケーションにするとapp.config/web.configの<applicationSettings>に記述される
  • スコープをユーザにするとapp.config/web.configの<userSettings>に記述される

ちなみにユーザースコープのパラメータはプログラムで変更保存が可能。

取得時の動作

CloudConfigurationManager.GetSetting(name)

これは、最初に*.cscfgを見に行き、無ければ、app.config/web.configの<appSettings>を見にいく

(Web)ConfigurationManager.AppSettings[name];

app.config/web.configの<appSettings> を見にいく

Properties.Settings.Default.<name>

app.config/web.configの<applicationSettings> を見にいく

15
20
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
15
20