public static void ReadOptionOverrides(ProjectItem sourceItem, bool display = true) { Project proj = sourceItem.ContainingProject; string jsonName = ""; foreach (ProjectItem item in proj.ProjectItems) { if (string.Equals(item.Name, OVERRIDE_FILE_NAME, StringComparison.InvariantCultureIgnoreCase)) { jsonName = item.FileNames[0]; break; } } if (!string.IsNullOrEmpty(jsonName)) { // it has been modified since last read - so read again try { overrides = JsonConvert.DeserializeObject <OptionsOverride>(File.ReadAllText(jsonName)); if (display) { VSHelpers.WriteOnOutputWindow(string.Format("Override file processed: {0}", jsonName)); } else { System.Diagnostics.Debug.WriteLine(string.Format("Override file processed: {0}", jsonName)); } } catch (Exception e) when(e is Newtonsoft.Json.JsonReaderException || e is Newtonsoft.Json.JsonSerializationException) { overrides = null; // incase the read fails VSHelpers.WriteOnOutputWindow(string.Format("Error in Override file: {0}", jsonName)); VSHelpers.WriteOnOutputWindow(e.Message); throw; } } else { if (display) { VSHelpers.WriteOnOutputWindow("Using Global Settings"); } else { System.Diagnostics.Debug.WriteLine("Using Global Settings"); } overrides = null; } }
internal static void SetOptionsOverrides(OptionsOverride optionsOverride) { overrides = optionsOverride; }