0

いくつかの Web 参照を持つレガシー プロジェクトがあり、環境 (ローカル、開発、ステージング、運用) に応じて異なるエンドポイントを構成したいと考えています。

私はこの記事を読みましたが、VS はSettings.settingsの代わりに と applicationSettings を使用appSettingsしているため、代わりに

this.Url = System.Configuration.ConfigurationSettings.AppSettings["foo_Api"]

使っているthis.Url = global::foo.Properties.Settings.Default.foo_Api;

私の app.config は次のようになります。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="foo.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <foo.Properties.Settings>
            <setting name="foo_Api" serializeAs="String">
                <value>http://myserver/server/Api.asmx</value>
            </setting>
        </foo.Properties.Settings>
    </applicationSettings>
</configuration>

での構成について読んだmachine.configことがありますが、同じマシンに異なる環境があるため、私の場合は機能しません。実行時に Url プロパティを変更することも、Web 参照のすべての使用法を変更する必要があるため、最善の解決策ではありません。

理想的にはappSettings、local.config を配置してエンドポイントの値を上書きできるようにしたいのですが、値を上書きする簡単な方法があれば問題ありapplicationSettingsません。

編集

これは dll プロジェクトです。これが何らかの影響を与えるかどうかはわかりません。

4

2 に答える 2

0

それが誰にでも役立つ場合:最終的にいくつかの調査の結果、私が見つけた最良の解決策は、Visual Studio構成プロファイルとWeb.config各環境の変換を追加することです. 次に、ローカルの Web 参照エンドポイントと、エンドポイントの値を置き換えるWeb.config変換をそれぞれに追加するだけです。Web.{environment}.config

詳細はこちら

于 2013-02-11T10:27:47.363 に答える
0

外部構成ファイルを applicationSettings セクションに含めることができるため、さまざまな環境に合わせて構成を調整できます。

<applicationSettings>
    <foo.Properties.Settings configSource="ConfigFolder\local.config">
    </foo.Properties.Settings>
</applicationSettings>

local.config:

<applicationSettings>
    <foo.Properties.Settings configSource="local.config">
        <setting name="foo_Api" serializeAs="String">
            <value>http://myserver/server/Api.asmx</value>
        </setting>
    </foo.Properties.Settings>
</applicationSettings
于 2013-01-29T12:34:22.933 に答える