In my extension that I am writing for Visual Studio 2015 I want to change the tab size and indent size as at work we have a different setting as when I am developing for opensource project (company history dating our C period). I have written the following code in my command class:
private const string CollectionPath = @"Text Editor\CSharp";
private void MenuItemCallback(object sender, EventArgs e)
{
var settingsManager = new ShellSettingsManager(ServiceProvider);
var settingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
var tabSize = settingsStore.GetInt32(CollectionPath, "Tab Size", -1);
var indentSize = settingsStore.GetInt32(CollectionPath, "Indent Size", -1);
if (tabSize != -1 && indentSize != -1)
{
settingsStore.SetInt32(CollectionPath, "Tab Size", 2);
settingsStore.SetInt32(CollectionPath, "Indent Size", 2);
}
}
When testing in an experimental hive it changes it when you step through the method but when you open the Options dialog it stays the original values. When you debug again the values stay the original.
What did I forget or did wrong?
By default, VS Code requires an explicit action to save your changes to disk, Ctrl+S. However, it's easy to turn on Auto Save , which will save your changes after a configured delay or when focus leaves the editor.
Settings. settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects. The Project Designer then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there.
How do you export VS Code extensions and settings? Run command palette Ctrl + Shift + P. Type VSC Export.
Directly access the Visual Studio options via the Properties
functionality in the EnvDTE assembly.
private void ChangeTabs(DTE vs, int newTabSize, int newIndentSize)
{
var cSharp = vs.Properties["TextEditor", "CSharp"];
EnvDTE.Property lTabSize = cSharp.Item("TabSize");
EnvDTE.Property lIndentSize = cSharp.Item("IndentSize");
lTabSize.Value = newTabSize;
lIndentSize.Value = newIndentSize;
}
private void ChangeSettings()
{
DTE vs = (DTE)GetService(typeof(DTE));
ChangeTabs(vs, 3, 3);
}
For reference: Controlling Options Settings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With