File tree Expand file tree Collapse file tree
BatchMuxer_SubEd_Console/classes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44using System . Diagnostics ;
55using System . IO ;
66using System . Linq ;
7+ using System . Reflection ;
78
89namespace BatchMuxer_SubEd_Console . Classes
910{ /// <summary>
@@ -105,20 +106,23 @@ public static bool RenameFile(FileInfo[] fi)
105106
106107 return hasRenamed;
107108 }
109+
108110 /// <summary>
109111 /// Update appsetting.json
110112 /// </summary>
111113 /// <param name="key">key to update</param>
112114 /// <param name="value">new value</param>
113115 public static void WriteToConfig(string key, string value)
114116 {
115- string json = File.ReadAllText("appsettings.json");
117+ string appSettingPath =
118+ Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "appsettings.json");
119+ string json = File.ReadAllText(appSettingPath);
116120 var application = new Application();
117121 JsonConvert.PopulateObject(json, application);
118122 dynamic jsonObj = JsonConvert.DeserializeObject(json);
119123 jsonObj["application"][key] = value;
120124 string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
121- File.WriteAllText("appsettings.json" , output);
125+ File.WriteAllText(appSettingPath , output);
122126 }
123127 }
124128}
You can’t perform that action at this time.
0 commit comments