2014-01-30 75 views

回答

8

通过提供带有参数/ResetSettings的设置文件,您可以实现导入

devenv /ResetSettings c:\full\path\to\your\own.vssettings 

这从VS2005起可以使用。

虽然可以进口在命令行中,据我所知是没有出口从命令行功能。对于您可以使用宏:

Sub ExportMacro() 
    DTE.ExecuteCommand("Tools.ImportandExportSettings", "/export:own.vssettings") 
End Sub 

或者从一个命令行C#应用程序(/参考EnvDte)

static void Main(string[] args) 
{ 
    var filename = "own.vssettings"; 
    var dte = (EnvDTE.DTE) System.Runtime.InteropServices.Marshal. 
           GetActiveObject("VisualStudio.DTE"); // version neutral 

    dte.ExecuteCommand("Tools.ImportandExportSettings", "/export:" + filename); 
} 

要从宏观和/或C#程序中导入取代/出口/进口

Msdn doc

+0

并从一个宏导入?什么是'owncsharp'? –

+0

切换导出到导入,冒号后面是什么文件名。 – rene

+1

任何方式只导入文件中的设置,无需重置所有内容? –

2

没有resetti NG,在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() 
} 
0

导入和导出,可以从PowerShell的。要将当前设置导出到$outFileName

这需要Visual Studio正在运行。 (你可以通过调用devenv来从脚本中完成)。

首先,添加在"附上文件的名称,以便在文件路径空间:

$filenameEscaped="`"$outFileName`"" 

$dte = [System.Runtime.InteropServices.Marshal]::GetActiveObject("VisualStudio.DTE.15.0") 
$dte.ExecuteCommand("Tools.ImportandExportSettings", '/export:'+$filenameEscaped) 

可选,退出:

$dte.ExecuteCommand("File.Exit") 

进口,要么使用/ResetSettings选项devenv的。可执行程序。或者,进口无复位:`

$dte.ExecuteCommand("Tools.ImportandExportSettings", '/import:'+$filenameEscaped) 

这个答案@刘若英的C#答案的端口。出于某种原因,我不得不指定确切版本的visual studio DTE.15.0

相关问题