在我为 Visual Studio 2015 编写的扩展中,我想更改制表符大小和缩进大小,因为在工作中我们有不同的设置,因为我在为开源项目开发时(公司历史可追溯到我们的 C 时期)。 我在命令类中编写了以下代码:
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);
}
}
在实验性配置单元中进行测试时,它会在您逐步执行该方法时更改它,但当您打开“选项”对话框时,它会保持原始值。 当您再次调试时,这些值保持不变。
我忘记了什么或做错了什么?
最佳答案
通过 EnvDTE 程序集中的 Properties
功能直接访问 Visual Studio 选项。
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);
}
关于c# - 在扩展中编写 Visual Studio 设置不会停留,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37130639/