Changing “Color theme” within a Visual Studio Extension

前端 未结 2 860
名媛妹妹
名媛妹妹 2021-02-05 12:03

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

2条回答
  •  逝去的感伤
    2021-02-05 12:48

    Here's the simplest way to do it:

    Overview:

    1. Use the "Import & Export Settings" feature to create two files: DarkTheme.vssettings and LightTheme.vssettings
    2. Programmatically invoke the Tools.ImportandExportSettings command to import those files at the appropriate time.

    Details:

    To create the two settings files:

    1. Launch Visual Studio and set the theme to "Light" through the UI
    2. From the Tools menu select "Import and Export Settings..."
    3. In the wizard, select "Export selected environment settings" and click "Next"
    4. In the "Which settings do you want to export?" page, deselect everything except "Options/Fonts and Colors" and click "Next"
    5. Name this file "Light.vssettings" and save it in a known location.
    6. Repeat steps 1 through 5 for the "Dark" theme, naming the file "Dark.vssettings".

    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.

提交回复
热议问题