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.

Sosian
  • 622
  • 11
  • 28
D.R.
  • 20,268
  • 21
  • 102
  • 205

2 Answers2

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\"")
Matthias
  • 15,919
  • 5
  • 39
  • 84
Sosian
  • 622
  • 11
  • 28
  • Thank you, great. Do you know per chance if you can export only some specific part of the configuration? – D.R. Apr 06 '16 at 13:32
  • 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. – Sosian Apr 06 '16 at 14:35
  • The command returns only TextEditor settings? Are you sure it does not return the last-selected settings? – D.R. Apr 06 '16 at 18:26
  • 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. – Sosian Apr 11 '16 at 09:06
  • For me it was crucial to have proper quotes. – Matthias Jul 18 '16 at 03:18
-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.

Inspyro
  • 358
  • 1
  • 8