Import/Export VS settings programmatically?
Asked Answered
A

2

4

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.

Aspersion answered 4/4, 2016 at 14:36 Comment(0)
S
2

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\"")
Shuman answered 6/4, 2016 at 13:26 Comment(5)
Thank you, great. Do you know per chance if you can export only some specific part of the configuration?Aspersion
No i dont think so. However, it seems that not all VSSettings are exported using this command. When comparing it to the .vssettings you get when you export using the UI, it seems like the command returns only TextEditor Settings.Shuman
The command returns only TextEditor settings? Are you sure it does not return the last-selected settings?Aspersion
Ok on further investigation it seems to not only be limited to TextEditor settings but seems to include a lot of other settings (maybe/probably all of them) But it is definitely not influenced by the last-selected settings in the Import/Export Wizard of Visual Studio 2015.Shuman
For me it was crucial to have proper quotes.Apparently
P
-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.

Pycno answered 18/7, 2016 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.