0

ユーザー接続文字列入力データを使用して、拡張インストーラ.MSIウィザードでweb.configファイルを作成しようとしています。web.configに保存して、追加の "config"拡張を追加します。

この結果、ファイルweb.config.configには余分なconfigが含まれていますが、どうして避けますか?

オープンまたは保存が正しくないと思いますか?

これはカスタムアクションです.MSIの中で、私はアドバンストインストーラから実行しましたが、それは私が思うような影響はありません。

[CustomAction] 
public static ActionResult EncryptConnStr(Session session) 
{ 
    try 
    { 
     var path = Path.Combine(@"C:\Users\radbyx\Documents", "web.config"); 
     var connStr = BuildConnStr("foo", "foo", "foo", "foo"); 

     Configuration config = ConfigurationManager.OpenExeConfiguration(path); 
     ConnectionStringsSection section = (ConnectionStringsSection)config.GetSection("connectionStrings"); 
     section.ConnectionStrings.Add(new ConnectionStringSettings(GetConnectionStringName(), connStr)); 

     // Encrypt 
     //section.SectionInformation.ProtectSection(ConnStrEncryptionKey); 

     // Save the configuration file. 
     config.Save(ConfigurationSaveMode.Modified, true); 

     return ActionResult.Success; 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show(ex.Message + "Trace: " + ex.StackTrace, ex.Message); 
     throw; 
    } 
} 

答えて

2

この動作は実行可能ではなく、設定ファイルへのパスを提供するために、期待しConfigurationManager.OpenExeConfigurationによって引き起こされます。

マップを受け取るオーバーロード使用し、明示的に設定ファイルを開くには:うわー、それはあなたが男だ、作品

var map = new ExeConfigurationFileMap { ExeConfigFilename = configFilePath }; 
configuration = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); 
+0

を。長い間前に尋ねたはずです。再び最高のサイトです。 – radbyx

+1

あなたは大歓迎です。お力になれて、嬉しいです :) –

関連する問題