Import/Export VS settings programmatically?

此生再无相见时 提交于 2019-12-23 12:50:04

问题


Is there a way to import/export Visual Studio settings via a Visual Studio Extension, i.e., via the Visual Studio API?

I want to export some specific settings to a local file, just like the VS Import and Export Settings Wizard does, however, without UI interaction of course.


回答1:


There is a Visual Studio Command named Tools.ImportandExportSettings

You can execute the Command with DTE2.ExecuteCommand

Import/Export example:

dte2.ExecuteCommand("Tools.ImportandExportSettings", "/export:\"C:/temp/setttings.vssettings\"")
dte2.ExecuteCommand("Tools.ImportandExportSettings", "/import:\"C:/temp/settings.vssettings\"")



回答2:


You could probably also use Roslyn:

var componentModel = (IComponentModel) Package.GetGlobalService(typeof(SComponentModel));
var visualStudioWorkspace = componentModel.GetService<VisualStudioWorkspace>();
visualStudioWorkspace.Options = visualStudioWorkspace.Options.WithChangedOption(CSharpFormattingOptions.NewLineForElse, false);

I haven't tried it, but the api suggests that you can indeed change global options via roslyn.



来源:https://stackoverflow.com/questions/36405630/import-export-vs-settings-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!