Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export/Import Visual Studio Settings from Command Line

How do I export/import VS 2010/2012 settings from the Command Line or using C#? Is it even possible without resorting to GUI Automation?

like image 727
Robin Rodricks Avatar asked Jan 30 '14 11:01

Robin Rodricks


People also ask

How do I export visual code settings?

How do you export VS Code extensions and settings? Run command palette Ctrl + Shift + P. Type VSC Export.

How do I export system configuration?

Click Setup, and then click Import and export settings. Under Import and Export, click to select Export Settings.


1 Answers

Without resetting, In PowerShell:

function Import-VisualStudioSettingsFile {
    [CmdletBinding()]
    param(
        [string] $FullPathToSettingsFile,
        [string] $DevEnvExe = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe",
        [int] $SecondsToSleep = 20 # should be enough for most machines
    )

    if(-not (Test-Path $DevEnvExe)) {
        throw "Could not find visual studio at: $DevEnvExe - is it installed?"
    }

    if(-not (Test-Path $FullPathToSettingsFile)) {
        throw "Could not find settings file at: $FullPathToSettingsFile"
    }

    $SettingsStagingFile = "C:\Windows\temp\Settings.vssettings" # must be in a folder without spaces
    Copy-Item $FullPathToSettingsFile $SettingsStagingFile -Force -Confirm:$false

    $Args = "/Command `"Tools.ImportandExportSettings /import:$SettingsStagingFile`""
    Write-Verbose "$Args"
    Write-Host "Setting Tds Options, will take $SecondsToSleep seconds"
    $Process = Start-Process -FilePath $DevEnvExe -ArgumentList $Args -Passthru
    Sleep -Seconds $SecondsToSleep #hack: couldnt find a way to exit when done
    $Process.Kill()
}
like image 157
Casper Leon Nielsen Avatar answered Oct 13 '22 21:10

Casper Leon Nielsen