diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
index ff02a8dbb2..02fb43d913 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
@@ -170,11 +170,10 @@ namespace Microsoft.PowerShell
internal class CommandLineParameterParser
{
internal static string[] validParameters = {
- "psconsoleFile",
"version",
"nologo",
"noexit",
-#if !CORECLR
+#if STAMODE
"sta",
"mta",
#endif
@@ -251,14 +250,6 @@ namespace Microsoft.PowerShell
}
}
- internal bool ImportSystemModules
- {
- get
- {
- return _importSystemModules;
- }
- }
-
internal bool SkipProfiles
{
get
@@ -416,6 +407,7 @@ namespace Microsoft.PowerShell
}
}
+#if STAMODE
internal bool StaMode
{
get
@@ -426,17 +418,14 @@ namespace Microsoft.PowerShell
}
else
{
-#if CORECLR
// Nano doesn't support STA COM apartment, so on Nano powershell has to use MTA as the default.
- return false;
-#else
+ // return false;
// Win8: 182409 PowerShell 3.0 should run in STA mode by default
return true;
-#endif
}
}
}
-
+#endif
///
///
@@ -554,10 +543,6 @@ namespace Microsoft.PowerShell
_noExit = true;
noexitSeen = true;
}
- else if (MatchSwitch(switchKey, "importsystemmodules", "imp"))
- {
- _importSystemModules = true;
- }
else if (MatchSwitch(switchKey, "noprofile", "nop"))
{
_skipUserInit = true;
@@ -728,7 +713,8 @@ namespace Microsoft.PowerShell
break;
}
}
-#if !CORECLR // explicit setting of the ApartmentState Not supported on NanoServer
+#if STAMODE
+ // explicit setting of the ApartmentState Not supported on NanoServer
else if (MatchSwitch(switchKey, "sta", "s"))
{
if (_staMode.HasValue)
@@ -1184,6 +1170,7 @@ namespace Microsoft.PowerShell
private string _helpText;
private bool _abortStartup;
private bool _skipUserInit;
+#if STAMODE
// Win8: 182409 PowerShell 3.0 should run in STA mode by default
// -sta and -mta are mutually exclusive..so tracking them using nullable boolean
// if true, then sta is specified on the command line.
@@ -1191,6 +1178,7 @@ namespace Microsoft.PowerShell
// if null, then none is specified on the command line..use default in this case
// default is sta.
private bool? _staMode = null;
+#endif
private bool _noExit = true;
private bool _explicitReadCommandsFromStdin;
private bool _noPrompt;
@@ -1203,7 +1191,6 @@ namespace Microsoft.PowerShell
private Collection _collectedArgs = new Collection();
private string _file;
private string _executionPolicy;
- private bool _importSystemModules = false;
}
} // namespace
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
index cb1bd8992b..a58906c913 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
@@ -1435,7 +1435,11 @@ namespace Microsoft.PowerShell
// NTRAID#Windows Out Of Band Releases-915506-2005/09/09
// Removed HandleUnexpectedExceptions infrastructure
- exitCode = DoRunspaceLoop(cpp.InitialCommand, cpp.SkipProfiles, cpp.Args, cpp.StaMode, cpp.ImportSystemModules, cpp.ConfigurationName);
+#if STAMODE
+ exitCode = DoRunspaceLoop(cpp.InitialCommand, cpp.SkipProfiles, cpp.Args, cpp.StaMode, cpp.ConfigurationName);
+#else
+ exitCode = DoRunspaceLoop(cpp.InitialCommand, cpp.SkipProfiles, cpp.Args, false, cpp.ConfigurationName);
+#endif
}
while (false);
@@ -1469,14 +1473,13 @@ namespace Microsoft.PowerShell
/// The process exit code to be returned by Main.
///
///
- private uint DoRunspaceLoop(string initialCommand, bool skipProfiles, Collection initialCommandArgs, bool staMode,
- bool importSystemModules, string configurationName)
+ private uint DoRunspaceLoop(string initialCommand, bool skipProfiles, Collection initialCommandArgs, bool staMode, string configurationName)
{
ExitCode = ExitCodeSuccess;
while (!ShouldEndSession)
{
- RunspaceCreationEventArgs args = new RunspaceCreationEventArgs(initialCommand, skipProfiles, staMode, importSystemModules, configurationName, initialCommandArgs);
+ RunspaceCreationEventArgs args = new RunspaceCreationEventArgs(initialCommand, skipProfiles, staMode, configurationName, initialCommandArgs);
CreateRunspace(args);
if (ExitCode == ExitCodeInitFailure) { break; }
@@ -1515,10 +1518,12 @@ namespace Microsoft.PowerShell
_runspaceRef.Runspace.Close();
_runspaceRef = null;
+#if STAMODE
if (staMode) // don't recycle the Runspace in STA mode
{
ShouldEndSession = true;
}
+#endif
}
return ExitCode;
@@ -1556,7 +1561,11 @@ namespace Microsoft.PowerShell
{
args = runspaceCreationArgs as RunspaceCreationEventArgs;
Dbg.Assert(args != null, "Event Arguments to CreateRunspace should not be null");
- DoCreateRunspace(args.InitialCommand, args.SkipProfiles, args.StaMode, args.ImportSystemModules, args.ConfigurationName, args.InitialCommandArgs);
+#if STAMODE
+ DoCreateRunspace(args.InitialCommand, args.SkipProfiles, args.StaMode, args.ConfigurationName, args.InitialCommandArgs);
+#else
+ DoCreateRunspace(args.InitialCommand, args.SkipProfiles, false, args.ConfigurationName, args.InitialCommandArgs);
+#endif
}
catch (ConsoleHostStartupException startupException)
{
@@ -1571,7 +1580,7 @@ namespace Microsoft.PowerShell
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
private void InitializeRunspace(string initialCommand, bool skipProfiles, Collection initialCommandArgs)
{
- DoCreateRunspace(initialCommand, skipProfiles, staMode: false, importSystemModules: false, configurationName: null, initialCommandArgs: initialCommandArgs);
+ DoCreateRunspace(initialCommand, skipProfiles, staMode: false, configurationName: null, initialCommandArgs: initialCommandArgs);
}
private bool LoadPSReadline()
@@ -1594,8 +1603,7 @@ namespace Microsoft.PowerShell
///
///
- //private void CreateRunspace(string initialCommand, bool skipProfiles, bool staMode, Collection initialCommandArgs)
- private void DoCreateRunspace(string initialCommand, bool skipProfiles, bool staMode, bool importSystemModules, string configurationName, Collection initialCommandArgs)
+ private void DoCreateRunspace(string initialCommand, bool skipProfiles, bool staMode, string configurationName, Collection initialCommandArgs)
{
Dbg.Assert(_runspaceRef == null, "runspace should be null");
#if !DEBUG
@@ -1682,11 +1690,12 @@ namespace Microsoft.PowerShell
// Record how long it took from process start to runspace open for telemetry.
_readyForInputTimeInMS = (DateTime.Now - Process.GetCurrentProcess().StartTime).TotalMilliseconds;
- DoRunspaceInitialization(importSystemModules, skipProfiles, initialCommand, configurationName, initialCommandArgs);
+ DoRunspaceInitialization(skipProfiles, initialCommand, configurationName, initialCommandArgs);
}
private void OpenConsoleRunspace(Runspace runspace, bool staMode)
{
+#if STAMODE
// staMode will have following values:
// On FullPS: 'true'/'false' = default('true'=STA) + possibility of overload through cmdline parameter '-mta'
// On NanoPS: always 'false' = default('false'=MTA) + NO possibility of overload through cmdline parameter '-mta'
@@ -1694,12 +1703,10 @@ namespace Microsoft.PowerShell
if (staMode)
{
// we can't change ApartmentStates on CoreCLR
-#if !CORECLR
runspace.ApartmentState = ApartmentState.STA;
-#endif
- runspace.ThreadOptions = PSThreadOptions.ReuseThread;
}
-
+#endif
+ runspace.ThreadOptions = PSThreadOptions.ReuseThread;
runspace.EngineActivityId = EtwActivity.GetActivityId();
s_runspaceInitTracer.WriteLine("Calling Runspace.Open");
@@ -1707,7 +1714,7 @@ namespace Microsoft.PowerShell
runspace.Open();
}
- private void DoRunspaceInitialization(bool importSystemModules, bool skipProfiles, string initialCommand, string configurationName, Collection initialCommandArgs)
+ private void DoRunspaceInitialization(bool skipProfiles, string initialCommand, string configurationName, Collection initialCommandArgs)
{
if (_runspaceRef.Runspace.Debugger != null)
{
@@ -1717,12 +1724,6 @@ namespace Microsoft.PowerShell
Executor exec = new Executor(this, false, false);
- // Run import system modules command
- if (importSystemModules)
- {
- Exception exception = InitializeRunspaceHelper("ImportSystemModules", exec, Executor.ExecutionOptions.None);
- }
-
if (!string.IsNullOrEmpty(configurationName))
{
// If an endpoint configuration is specified then create a loop-back remote runspace targeting
@@ -3015,28 +3016,28 @@ namespace Microsoft.PowerShell
///
///
///
- ///
///
///
internal RunspaceCreationEventArgs(string initialCommand,
bool skipProfiles,
bool staMode,
- bool importSystemModules,
string configurationName,
Collection initialCommandArgs)
{
InitialCommand = initialCommand;
SkipProfiles = skipProfiles;
+#if STAMODE
StaMode = staMode;
- ImportSystemModules = importSystemModules;
+#endif
ConfigurationName = configurationName;
InitialCommandArgs = initialCommandArgs;
}
internal string InitialCommand { get; set; }
internal bool SkipProfiles { get; set; }
+#if STAMODE
internal bool StaMode { get; set; }
- internal bool ImportSystemModules { get; set; }
+#endif
internal string ConfigurationName { get; set; }
internal Collection InitialCommandArgs { get; set; }
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs
index 227ee91aba..c5e0d332c0 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs
@@ -25,18 +25,6 @@ namespace Microsoft.PowerShell
{
return Start(null, bannerText, helpText, null, args);
}
-#else
- /// Entry point in to ConsoleShell. This method is called by main of minishell.
- /// Configuration information which is used to create Runspace.
- /// Banner text to be displayed by ConsoleHost
- /// Help text for minishell. This is displayed on 'minishell -?'.
- /// Commandline parameters specified by user.
- /// An integer value which should be used as exit code for the process.
- public static int Start(RunspaceConfiguration configuration, string bannerText, string helpText, string[] args)
- {
- return Start(configuration, bannerText, helpText, null, args);
- }
-#endif
///
///
diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs
index e47498fdf5..e20aa7a30c 100644
--- a/src/System.Management.Automation/engine/InitialSessionState.cs
+++ b/src/System.Management.Automation/engine/InitialSessionState.cs
@@ -4162,14 +4162,6 @@ End
}
";
- ///
- /// This is the default function to use for 'Import System Modules'.
- ///
- ///
- /// Win8: 320909. Retaining the original definition to ensure backward compatability.
- ///
- private static string s_importSystemModulesText = @"";
-
///
/// This is the default function to use for clear-host. On Windows it rewrites the
/// host, and on Linux, it delegates to the native binary, 'clear'.
@@ -4971,8 +4963,6 @@ if($paths) {
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd..", "Set-Location ..", isProductCode: true),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd\\", "Set-Location \\", isProductCode: true),
- // Win8: 320909. Retaining the original definition to ensure backward compatability.
- SessionStateFunctionEntry.GetDelayParsedFunctionEntry("ImportSystemModules", s_importSystemModulesText, isProductCode: true),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Pause",
string.Concat("$null = Read-Host '", CodeGeneration.EscapeSingleQuotedStringContent(RunspaceInit.PauseDefinitionString),"'"), isProductCode: true)
};