Import/Export VS settings programmatically?

2019-06-26 03:49发布

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.

2条回答
太酷不给撩
2楼-- · 2019-06-26 04:04

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.

查看更多
聊天终结者
3楼-- · 2019-06-26 04:10

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\"")
查看更多
登录 后发表回答