5.1.0-preview-06 does not contain Runspace.DefaultRunspace.CreateNestedPipeline()
bergmeister opened this issue · 2 comments
In PS 5.1, 6.0.2 and 6.1 (daily) the following works without errors:
[runspace]::DefaultRunspace.CreateNestedPipeline()
However, PS Standard 5.1.0-preview-06
does not contain a reference to Runspace.DefaultRunspace.CreateNestedPipeline()
, leading to a compilation error.
This is by-design. We don't want to promote use of the v1 Pipeline API going forward. Let me know if this is a major concern.
So this is a blocker for me. I'm in the middle of researching the ability to migrate from a DotNet Framework 4.6 class library to DotNetStandard 2.0, in order to support both PowerShell 5.x and PowerShellCore. I have existing code that writes to the Verbose stream from within my class library that needs to be captured via console redirect, and uses the CreateNestedPipeline
API to achieve that.
public static void Verbose(string msg, string source)
{
if (Namspace.StaticClass1.ShowConsoleVerboseOutput || Namspace.StaticClass1.EnableVerbose )
{
var rs = Runspace.DefaultRunspace
.CreateNestedPipeline("Write-Verbose \"[" + source + "] " + msg.Replace("\"", "\"\"") + "\" -v", false)
.Invoke();
}
}
What is the alternative?
Please see this Stackoverflow thread on the topic, and proposed working code.