diff --git a/src/Microsoft.PowerShell.CoreConsoleHost/main.cs b/src/Microsoft.PowerShell.CoreConsoleHost/main.cs
index 13daf43fc..ba3f0be18 100644
--- a/src/Microsoft.PowerShell.CoreConsoleHost/main.cs
+++ b/src/Microsoft.PowerShell.CoreConsoleHost/main.cs
@@ -9,6 +9,7 @@ namespace Microsoft.PowerShell.CoreConsoleHost
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
+ using System.Linq;
using PowerShell = System.Management.Automation.PowerShell;
public static class Program
@@ -562,27 +563,78 @@ OPTIONS
this.myHost.UI.Write(prompt);
- ConsoleReadLine.ReadResult result = consoleReadLine.Read(false, initialCommand);
-
- switch(result.state)
+ string input;
+ if (TryInvokeUserDefinedReadLine(out input, true))
{
- case ConsoleReadLine.ReadResult.State.Abort:
- incompleteLine = false;
- partialLine = string.Empty;
- initialCommand = String.Empty;
- break;
- case ConsoleReadLine.ReadResult.State.Redraw:
- initialCommand = result.command;
- break;
- case ConsoleReadLine.ReadResult.State.Complete:
- default:
- this.Execute(result.command);
- initialCommand = String.Empty;
- break;
+ this.Execute(input);
+ }
+ else
+ {
+ ConsoleReadLine.ReadResult result = consoleReadLine.Read(false, initialCommand);
+
+ switch(result.state)
+ {
+ case ConsoleReadLine.ReadResult.State.Abort:
+ incompleteLine = false;
+ partialLine = string.Empty;
+ initialCommand = String.Empty;
+ break;
+ case ConsoleReadLine.ReadResult.State.Redraw:
+ initialCommand = result.command;
+ break;
+ case ConsoleReadLine.ReadResult.State.Complete:
+ default:
+ this.Execute(result.command);
+ initialCommand = String.Empty;
+ break;
+ }
}
}
}
+ ///
+ /// Helper function to test if PSReadLine or another alternate ReadLine has been loaded
+ ///
+ const string CustomReadlineCommand = "PSConsoleHostReadLine";
+ private bool TryInvokeUserDefinedReadLine(out string input, bool useUserDefinedCustomReadLine)
+ {
+ if (useUserDefinedCustomReadLine)
+ {
+ var runspace = this.myHost.Runspace;
+ if (runspace != null
+ && runspace.ExecutionContext.EngineIntrinsics.InvokeCommand.GetCommands(CustomReadlineCommand, CommandTypes.Function | CommandTypes.Cmdlet, nameIsPattern: false).Any())
+ {
+ try
+ {
+ PowerShell ps;
+ if ((runspace.ExecutionContext.EngineHostInterface.NestedPromptCount > 0) && (Runspace.DefaultRunspace != null))
+ {
+ ps = PowerShell.Create(RunspaceMode.CurrentRunspace);
+ }
+ else
+ {
+ ps = PowerShell.Create();
+ ps.Runspace = runspace;
+ }
+
+ var result = ps.AddCommand(CustomReadlineCommand).Invoke();
+ if (result.Count == 1)
+ {
+ input = PSObject.Base(result[0]) as string;
+ return true;
+ }
+ }
+ catch (Exception e)
+ {
+ CommandProcessorBase.CheckForSevereException(e);
+ }
+ }
+ }
+
+ input = null;
+ return false;
+ }
+
///
/// Method to handle the Debugger DebuggerStop event.
///
diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
index 206d95a18..ddac1ac97 100644
--- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
+++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
@@ -2010,7 +2010,8 @@ namespace Microsoft.PowerShell.Commands
}
// Test the required .NET Framework version
- Version requestedDotNetFrameworkVersion;
+ Version requestedDotNetFrameworkVersion = new Version (0, 0, 0, 0);
+#if !CORECLR
if (
!GetScalarFromData(data, moduleManifestPath, "DotNetFrameworkVersion", manifestProcessingFlags,
out requestedDotNetFrameworkVersion))
@@ -2044,6 +2045,7 @@ namespace Microsoft.PowerShell.Commands
WriteVerbose(cannotDetectNetFrameworkVersionMessage);
}
}
+#endif
// HelpInfo URI
string helpInfoUri = null;