Execute PowerShell code in NuGet PowerShell host from other tool window or macro

Nov 24, 2010 at 1:33 PM

I would like to execute PowerShell script code  in the NuGet PowerShell host (Package Manager Console) initiated from a macro or tool window.

Is there a way to do this?

Nov 24, 2010 at 2:29 PM

We are not exposing any automation model from the Package Manager console, so this is not possible. What is your scenario? 

Nov 24, 2010 at 2:43 PM

I could see adding context menus that call into functions that are exposed in my init.ps1

sent from my mobile

Nov 24, 2010 at 2:50 PM

My scenario is as follows:

I have a tool window which we call the "Factory Guide", this is a tree control with actions. These actions range from opening a certain document, adding a project, or runnin a test suite.

The "Factory Guide" currently has an embedded powershell host that provides access to the Visual Studio object model, just like the NuGet Package Manager Console.

See http://solutionsfactory.macaw.nl/images/16-9/Factory%20Guide.png for a screenshot of the Factory Guide.

I would prefer to execute scripts in the NuGet Package Manager Console to execute my actions, because then I can distribute packages with functionality using NuGet.

I also would like to be able to get back results from scripts executed in the NuGet Package Manager Console so I can populate the Factory Guide with actions based on installed packages, and in this way provide a UI to available actions.

In order to do this I need one piece of functionality:

Execute a piece of powershell code in the context of the NuGet Package Manager Console, and get back the result.

Nov 25, 2010 at 10:43 AM
svdoever wrote:

I would prefer to execute scripts in the NuGet Package Manager Console to execute my actions, because then I can distribute packages with functionality using NuGet.

I also would like to be able to get back results from scripts executed in the NuGet Package Manager Console so I can populate the Factory Guide with actions based on installed packages, and in this way provide a UI to available actions.

Can you clarify a bit more? What do you mean by "execute scripts in the NuGet Package Manager console to execute my actions"? Do you want to install/uninstall packages directly from your tool window? If so, you may be able to reference the NuGet.VisualStudio.dll (and the NuGet.Core.dll) and call the public APIs exposed from it. The NuGet console basically does the same thing.

Nov 25, 2010 at 11:47 PM

Sorry I was unclear. I want to do the following:

When I build up the contents of my tool window (the Factory Guide actions tree), Iwant to populate my actions based on the result of functions installed by the user through a NuGet package.

For example I install the NuGet package 'SharePoint2010Factory', If I have a SharePoint2010 project I want to populate my Factory Guide tool window with actions returned to me by calling the function Get-SharePoint2010FactoryGuideActions (installed by the SharePoint2010Factory NuGet package). The set of actions to be added to the Factory Guide consists of an action name and the powershell code to execute for the action. The execution of the PowerShell must be done in the context of the NuGet console, because I can execute the same functions from the Factory Guide as you can execute fron the NuGet console.

I hope this clearifies my scenario.

Nov 27, 2010 at 12:42 AM

I see. I don't believe this can be done currently. After we install a package, we invoke install.ps1. It is up to the script file to provide functions/cmdlets to the PowerShell host. I'm not sure if there is a clean way to capture them.