从命令行导出/导入Visual Studio设置
答
通过提供带有参数/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#程序中导入取代/出口与/进口
答
没有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()
}
答
导入和导出,可以从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
。
+更多信息在:http://*.com/a/3636294/492 –