简体   繁体   中英

Control Visual Studio 2017 from command line/package manager/powershell

I am aware of the PowerShell object $dte , but I am wondering if their are other possibilities to control actions like Rebuild Solution , Clean Solution etc?

As my PowerShell prompt ist opened anyway all the time (using Posh-Git, .etc) it would be handy to control other Visual Studio Tasks straight from the PS console.

The DTE documentation for SolutionBuild has some VB code that was pretty easy to translate to Powershell:

$dte = [System.Runtime.InteropServices.Marshal]::GetActiveObject('VisualStudio.DTE')
$sb = $dte.Solution.SolutionBuild
$sb.SolutionConfigurations['Debug'].Activate  #Or maybe you want 'Release'
$sb.Build() 

The SolutionBuild interface has other interesting methods: Clean() , Debug() and Run() . You were probably already aware, but the console needs to be running as Administrator to get the DTE handle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM