Do commandBars work in the nuget version?

Mar 14, 2014 at 10:23 PM
If I install through NuGet (that is, if I just Import-Module from the Package Manager Console), I can do something like this:
new-item dte:\commandBars -Name ShellTools
new-item dte:\commandBars\ShellTools -name "Run Script" -type button -action { 
  ls DTE:\SelectedItems\ProjectItems | % { & $_.FileName }
}
But actually clicking the button seems to freeze things up... permanently
Coordinator
Mar 16, 2014 at 1:56 AM
Hey Joel;

Can you post the value of $psversiontable in this thread?

Based on the use of the -action parameter name, it looks like you may be using an old version of StudioShell. In the past the commandbar handling was done through the studioshell addin and was touchy; in the newest release this has been changed to use event handlers on the command bar control. The jury is still out on whether this is less touchy.

I altered your code a bit, and it seems to work fine against the 1.6.2.0 build:
Package Manager Console Host Version 2.2.31210.9045

Type 'get-help NuGet' to see all available NuGet commands.

PM> import-module studioshell
PM> new-item dte:\commandBars -Name ShellTools


    Location: StudioShell.Provider\PSDTE::commandBars
    Command Bar: CommandBars
    Available Operations: d+ <      


           Id       Index Type                 Name                    
---------- --       ----- ----                 ----                    
           0        486   msoBarTypeNormal     ShellTools              


PM> new-item dte:\commandBars\ShellTools -name "Run Script" -type button -value { ls DTE:\SelectedItems\ProjectItems | % { & $_.FileName } }


    Location: StudioShell.Provider\PSDTE::commandBars\ShellTools
    Command Bar: ShellTools
    Available Operations: d+~<      


           Id       Index Type                 Name                    
---------- --       ----- ----                 ----                    
           1        1     msoControlButton     Run Script              
Of course, I'm not settling for "it works on my machine". Get me that version information (as well as the VS and nuget versions please) and let's take it from there.
Mar 18, 2014 at 5:45 AM
Edited Mar 18, 2014 at 6:03 AM
Hmm, can you click that though?

Maybe I've done something wrong ;-) I installed it with NuGet, but then copied it out to my modules path ...
I can't import the StudioShell module, only the StudioShell.Provider -- I assumed that was normal without the extension?
[22+]:  Import-Module StudioShell.Provider
[24+]:  $PSVersionTable

Name                           Value                
----                           -----                
PSVersion                      4.0                  
StudioShellVersion             1.6.2.0              
WSManStackVersion              3.0                  
SerializationVersion           1.1.0.1              
CLRVersion                     4.0.30319.34011      
BuildVersion                   6.3.9600.16394       
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0} 
PSRemotingProtocolVersion      2.2                  


[26+]:  new-item dte:\commandBars -Name ShellTools


    Location: StudioShell.Provider\PSDTE::commandBars
    Command Bar: CommandBars
    Available Operations: d+ <      


           Id       Index Type                 Name                    
---------- --       ----- ----                 ----                    
           0        517   msoBarTypeNormal     ShellTools              


[28+]:  new-item dte:\commandBars\ShellTools -name "Run Script" -type button -value { ls DTE:\SelectedItems\ProjectItems | % { & $_.FileName } }


    Location: StudioShell.Provider\PSDTE::commandBars\ShellTools
    Command Bar: ShellTools
    Available Operations: d+~<      


           Id       Index Type                 Name                    
---------- --       ----- ----                 ----                    
           1        1     msoControlButton     Run Script              
Tangent: LOL at the fact that it increments the number twice between prompts. Wait, why? Get-History. OMG, I can't believe NuGet is putting the "prompt" function into the history. Why can't the write a decent host! WTF.

So yeah, anyway ... that code all works, but if I click the button Visual Studio just .... locks up completely.
Coordinator
Mar 18, 2014 at 8:35 PM
Yeah, I can click it and it works fine :\

Can you try something for me? Change the scriptblock for the button to something innocuous (or at least something that doesn't invoke something else), like maybe:
new-item dte:\commandBars\ShellTools -name "Run Script" -type button -value { get-date|out-outputpane }
Mar 19, 2014 at 5:46 AM
As frustrating as this is to me ... that works ;-)

I tried tacking Out-OutputPane onto my other one to see if I could tell what's going on, and it still locked up (I'm going to leave it running, maybe it will come back eventually). I suppose the script must be running slowly for some reason, I know that I tried something like: ls | out-tasklist in the NuGet console and it spews errors REALLY, REALLY slowly.
Coordinator
Mar 19, 2014 at 11:24 AM
Well sh!t. This may be caused by the way Nuget leverages the VS COM object model. I recall Oisin mentioning something about switching apartment models a few versions back, expecting VS interaction to slow by 4x or something. hmmmm......

perhaps measuring the execution time of the different parts of the executing scriptblock would provide some insight?