Write to NuGet Package Manager Console from C#

Topics: Ecosystem
Jan 20, 2014 at 9:03 AM
Hi guys,
i'm writing cmdlets which should be available through the Package Manager Console. The Cmdlets will call some C# Methods. I couldn't figure out how to write to the Package Manager Console from C# without beeing in a Cmdlet.

I found the following article on so: http://stackoverflow.com/questions/13037360/console-writeline-from-with-the-nuget-package-manager-console
var runspace = Runspace.DefaultRunspace;
var pipeline = runspace.CreatePipeline("Write-Host '" + message + "'", false);
But it doesn't work, i get some exception: "Pipeline not run because a pipeline is already running. Pipelines cannot be run concurrently."

All the output in the C# Methods are behind a ILog interface, so i can add any implementation for powershell. But i don't know how to connect to the the runspace/pshost.

Feb 10, 2014 at 10:57 AM
According to the error message you should use CreateNestedPipeline() instead of CreatePipeline().
May 21, 2014 at 3:05 PM
somehow i never rever answered, but still i wan't to say "thank you"! Beter late than never :)

I tried that before, but got the same exception (because of another mistake) which misleaded me. Could fix everything and it works with CreateNestedPipeline().