これは一般的なシナリオであり、さまざまな解決方法があります。1 つの方法は、config transformsを使用することです。や と同じようにWeb.Customer1.config、 、 などを使用できます。顧客固有の変換ファイルでは、顧客がカスタマイズしたいのみを「オーバーライド」できます。Web.Customer2.configWeb.Debug.configWeb.Release.configappSettings
さまざまな変換を作成するには、まずさまざまなプロジェクト プラットフォームを作成します。Visual Studio 構成マネージャーに移動し、ConfigurationWeb プロジェクト (またはカスタマイズされた構成設定が必要な任意のプロジェクト) の列で、ドロップダウンをクリックしてから をクリックします<New...>。新しいプロジェクト構成Customer1または任意の名前を付け、 のボックスをオンにして、そのドロップダウンからCopy settings from選択Releaseします。チェックボックスにもチェックをCreate new solution configurations入れます。
最後に、web.configファイルを右クリックして をクリックしますAdd config transform。これにより、テンプレートWeb.Customer1.configファイルが生成されます。config 変換属性appSettingsを使用して、必要に応じてオーバーライドするように編集します。次に、ソリューション ビルド構成xdt:を使用してプロジェクトを発行できます。Customer1ビルドの一環としてweb.configが変換され、web.config顧客ごとに異なるファイルが作成されます。これを使用して、さまざまな展開用にプロジェクトをカスタマイズすることもできます。つまり、db 接続文字列、smtp サーバー、文字通り XML 構成ファイル内のすべてを変更します。
最後の考えとして、各Web.Xyx.configファイルを右クリックし、プロパティを選択して、それを に設定しBuild ActionてNoneください。
例:
ベース web.config
<appSettings>
<add key="CommonProperty1" value="[for all customers]" />
<add key="CommonProperty2" value="[for all customers]" />
<add key="CommonProperty3" value="[for all customers]" />
<add key="CustomProperty1" value="[for one customer]" />
<add key="CustomProperty2" value="[for one customer]" />
<add key="CustomProperty3" value="[for one customer]" />
<appSettings>
web.Customer1.config
<appSettings>
<add key="CustomProperty1" value="The Ohio State University" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="CustomProperty2" value="Scarlet" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="CustomProperty3" value="Gray" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<appSettings>
web.Customer2.config
<appSettings>
<add key="CustomProperty1" value="Michigan University" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="CustomProperty2" value="Blue" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="CustomProperty3" value="Maize" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<appSettings>