public static PowerShellContextService Create(ILogger logger) { PowerShellContextService powerShellContext = new PowerShellContextService(logger, null, isPSReadLineEnabled: false); HostStartupInfo testHostDetails = new HostStartupInfo( "PowerShell Editor Services Test Host", "Test.PowerShellEditorServices", new Version("1.0.0"), null, TestProfilePaths, new List <string>(), new List <string>(), PSLanguageMode.FullLanguage, null, 0, consoleReplEnabled: false, usesLegacyReadLine: false); powerShellContext.Initialize( TestProfilePaths, PowerShellContextService.CreateRunspace( testHostDetails, powerShellContext, new TestPSHostUserInterface(powerShellContext, logger), logger), true); return(powerShellContext); }
public static PowerShellContextService Create(ILogger logger) { PowerShellContextService powerShellContext = new PowerShellContextService(logger, null, isPSReadLineEnabled: false); // We intentionally use `CreateDefault2()` as it loads `Microsoft.PowerShell.Core` only, // which is a more minimal and therefore safer state. var initialSessionState = InitialSessionState.CreateDefault2(); // We set the process scope's execution policy (which is really the runspace's scope) to // `Bypass` so we can import our bundled modules. This is equivalent in scope to the CLI // argument `-ExecutionPolicy Bypass`, which (for instance) the extension passes. Thus // we emulate this behavior for consistency such that unit tests can pass in a similar // environment. if (VersionUtils.IsWindows) { initialSessionState.ExecutionPolicy = ExecutionPolicy.Bypass; } HostStartupInfo testHostDetails = new HostStartupInfo( "PowerShell Editor Services Test Host", "Test.PowerShellEditorServices", new Version("1.0.0"), null, TestProfilePaths, new List <string>(), new List <string>(), initialSessionState, null, 0, consoleReplEnabled: false, usesLegacyReadLine: false, bundledModulePath: BundledModulePath); InitialRunspace = PowerShellContextService.CreateTestRunspace( testHostDetails, powerShellContext, new TestPSHostUserInterface(powerShellContext, logger), logger); powerShellContext.Initialize( TestProfilePaths, InitialRunspace, ownsInitialRunspace: true, consoleHost: null); return(powerShellContext); }