Ich habe ein kleines Programm geschrieben, das ich App.config Datei ein einfaches AppSetting für eine andere Anwendung ändern kann, und speichern Sie die Änderungen:Kann ConfigurationManager XML-Kommentare in Save() speichern?
//save a backup copy first.
var cfg = ConfigurationManager.OpenExeConfiguration(pathToExeFile);
cfg.SaveAs(cfg.FilePath + "." + DateTime.Now.ToFileTime() + ".bak");
//reopen the original config again and update it.
cfg = ConfigurationManager.OpenExeConfiguration(pathToExeFile);
var setting = cfg.AppSettings.Settings[keyName];
setting.Value = newValue;
//save the changed configuration.
cfg.Save(ConfigurationSaveMode.Full);
Diese gut, bis auf eine Nebenwirkung funktioniert. Die neu gespeicherte .config-Datei verliert alle ursprünglichen XML-Kommentare, jedoch nur innerhalb des AppSettings-Bereichs. Ist es möglich, XML-Kommentare aus der ursprünglichen AppSettings-Konfigurationsdatei beizubehalten?
Here's a pastebin of the full source if you'd like to quickly compile and run it.
Bekam das gleiche Problem hier mit .NET 4.0 – pipelinecache
Auch festgestellt, dass es nur in der appSettings Abschnitt tut. – pipelinecache
Kommentare bleiben auch im Rest meiner .config-Datei erhalten. Ich habe meinen Beitrag aktualisiert, um dies zu berücksichtigen. –