2

MVC サイトをテスト サーバーにデプロイすると、別のデータベースに接続されるため、別の接続文字列が必要になります。

通常、これはWeb.configの変換を使用して変更できますが、残念ながら、接続文字列がテキスト ファイルで決定される NopCommerce ソリューションを使用しています: App_Data/Settings.txt

では、 「Debug」や「TeamCityDebug」などのビルド構成に応じて、この Settings.txt ファイルの行を変更する方法について、誰かアイデアはありますか?

ビルド イベント (以下を参照) について考えましたが、たとえば、「デバッグ」だけでなく、すべてのビルド構成で発生します。

ここに画像の説明を入力

4

3 に答える 3

1

提案に感謝しますが、最終的に複数の"<something>settings.txt"ファイルを作成し、単純なビルド後のイベント (コマンド ライン アクション) を使用して、目的のファイルを正しいディレクトリに必要な名前でコピーしました"Settings.txt"。アプリケーションはこのファイルを取得し、その中の connectionStrings を使用します。

ビルド後のイベントに次を追加しました。

if $(ConfigurationName) == TeamCityDebug copy /Y "$(ProjectDir)App_Data\TeamCitySettings.txt" 
                                                 "$(ProjectDir)App_Data\Settings.txt"

if $(ConfigurationName) == Release copy /Y "$(ProjectDir)App_Data\LocalSettings.txt"  
                                           "$(ProjectDir)\App_Data\Settings.txt"
于 2013-04-24T10:32:51.660 に答える
1

You can write a console application to process your Setting.txt invoke your console application in your pre-build event

replace.exe "servera" "serverb" "....\Settings.txt" --for example

in your console application code

static void Main(string[] args)
{
    FileStream fs = new FileStream(args[3],FileMode.OpenOrCreate);
    StreamReader sr = new StreamReader(fs);
    StreamWriter sw = new StreamWriter(fs);
    string content = sr.ReadToEnd();            
    content = content.Replace(args[0], args[1]);
    fs.Position = 0;
    sw.Write(content);            
}
于 2013-04-24T08:55:08.080 に答える
0

以下を使用できます。

#if DEBUG
    //Load connection from debug file
#else
    //Load connection from release file
#endif

TeamCityDebug のようなカスタム ビルド構成を使用できるかどうかはわかりませんが、試してみることはできます...

于 2013-04-24T10:01:10.397 に答える