I'm working on a visual studio extension and I need to retrieve the current Visual Studio theme Id. In the past (Visual Studio 13), this value was stored in the registry and was easily accessible using:
var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\VisualStudio\12.0\General");
var Id = (string)key.GetValue("CurrentTheme", string.Empty);
This does not work anymore since the theme id is no longer stored in the registry. Does anyone know how to access the theme id in VS 2022?
Visual Studio 2022 maps private registry hive to regular registry keys when running. It's private registry is stored in your AppData
folder. You can find privateregistry.bin
file from the following folder.
C:\Users\{useraccount}\AppData\Local\Microsoft\VisualStudio\17.0_xxxx\
To get the current visual studio Them-Id from stored registry keys, you can use regedit.exe
to load a private hive.
1.Select the HKEY_USERS
node, and click the File > Load Hive… menu.
2.Select the privateregistry.bin
file, give a name to the hive (e.g: “VS20222PrivateRegistry”)
3.You can see the 17.0_xxx
key populated as usual (note: use File > Unload Hive when done)
Test Result:
var key = Microsoft.Win32.Registry.Users.OpenSubKey("VS2022PrivateRegistry\\Software\\Microsoft\\VisualStudio\\17.0_92f92fc9\\Theme");
var Id = (string)key.GetValue("BackupThemeId", string.Empty);
In my case,{1ded0138-47ce-435e-84ef-9ec1f439b749}
represents Dark theme i use in my current VS.
Besides, as @user246821 notes in above comment, you can get the value from CurrentSettings.vssettings
file.
C:\Users\{useraccount}\AppData\Local\Microsoft\VisualStudio\17.0_xxx\Settings
<Theme Id="{1DED0138-47CE-435E-84EF-9EC1F439B749}"/>