I\'m writing a Visual Studio extension in C# that I hope will change the color theme depending on the time of day (After sunset the dark theme will be applied - at sunrise eithe
ShellSettingsManager
enables you to access and modify Visual Studio settings but only in the Windows registry. Any changes you make will not be picked up by Visual Studio until it is restarted because VS reads settings from the registry only when it starts. So this is the wrong approach.
To both change settings and apply them without requiring a restart, you will have to use DTE2.Properties as discussed in here. The following code snippet shows all the settings that can be changed programmatically from the Environment/General page (this is where you can change the theme):
EnvDTE.Properties generalProps = dte2Obj.Properties["Environment", "General"];
for (int i = 1; i <= generalProps.Count; ++i)
{
System.Diagnostics.Debug.WriteLine(
generalProps.Item(i).Name + ": " + generalProps.Item(i).Value);
}
By default in VS2013, this code will produce the following output:
AnimationSpeed: 5
RichClientExperienceOptions: 65535
WindowMenuContainsNItems: 10
CloseButtonActiveTabOnly: True
UseTitleCaseOnMenu: False
AutoAdjustExperience: True
Animations: True
AutohidePinActiveTabOnly: False
ShowStatusBar: True
MRUListContainsNItems: 10
All of these settings can be changed and VS will immediately apply the changes. The problem is that there is no property that enables you to change the theme. That's why I think it cannot be done.
Here's the simplest way to do it:
Overview:
Details:
To create the two settings files:
To import these files programmatically use DTE.ExecuteCommand with the "/import" parameter like this:
Add a reference to EnvDTE.dll if you don't have it already.
var dte = GetService(typeof(EnvDTE._DTE)) as EnvDTE.DTE;
dte.ExecuteCommand("Tools.ImportandExportSettings", @"/import:""C:\yourpath\LightTheme.vssettings""");
I hope that helps.