move processing of -WorkingDirectory
before processing of profiles (#8079)
This commit is contained in:
parent
b3f315eb15
commit
b1e2745b53
|
@ -1614,6 +1614,31 @@ namespace Microsoft.PowerShell
|
|||
|
||||
Executor exec = new Executor(this, false, false);
|
||||
|
||||
// If working directory was specified, set it
|
||||
if (s_cpp != null && s_cpp.WorkingDirectory != null)
|
||||
{
|
||||
Pipeline tempPipeline = exec.CreatePipeline();
|
||||
var command = new Command("Set-Location");
|
||||
command.Parameters.Add("LiteralPath", s_cpp.WorkingDirectory);
|
||||
tempPipeline.Commands.Add(command);
|
||||
|
||||
Exception exception;
|
||||
if (IsRunningAsync)
|
||||
{
|
||||
exec.ExecuteCommandAsyncHelper(tempPipeline, out exception, Executor.ExecutionOptions.AddOutputter);
|
||||
}
|
||||
else
|
||||
{
|
||||
exec.ExecuteCommandHelper(tempPipeline, out exception, Executor.ExecutionOptions.AddOutputter);
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
_lastRunspaceInitializationException = exception;
|
||||
ReportException(exception, exec);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(configurationName))
|
||||
{
|
||||
// If an endpoint configuration is specified then create a loop-back remote runspace targeting
|
||||
|
@ -1694,31 +1719,6 @@ namespace Microsoft.PowerShell
|
|||
TelemetryAPI.ReportStartupTelemetry(this);
|
||||
#endif
|
||||
|
||||
// If working directory was specified, set it
|
||||
if (s_cpp != null && s_cpp.WorkingDirectory != null)
|
||||
{
|
||||
Pipeline tempPipeline = exec.CreatePipeline();
|
||||
var command = new Command("Set-Location");
|
||||
command.Parameters.Add("LiteralPath", s_cpp.WorkingDirectory);
|
||||
tempPipeline.Commands.Add(command);
|
||||
|
||||
Exception exception;
|
||||
if (IsRunningAsync)
|
||||
{
|
||||
exec.ExecuteCommandAsyncHelper(tempPipeline, out exception, Executor.ExecutionOptions.AddOutputter);
|
||||
}
|
||||
else
|
||||
{
|
||||
exec.ExecuteCommandHelper(tempPipeline, out exception, Executor.ExecutionOptions.AddOutputter);
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
_lastRunspaceInitializationException = exception;
|
||||
ReportException(exception, exec);
|
||||
}
|
||||
}
|
||||
|
||||
// If a file was specified as the argument to run, then run it...
|
||||
if (s_cpp != null && s_cpp.File != null)
|
||||
{
|
||||
|
|
|
@ -567,6 +567,25 @@ foo
|
|||
$LASTEXITCODE | Should -Be $ExitCodeBadCommandLineParameter
|
||||
$output | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "-WorkingDirectory should be processed before profiles" {
|
||||
|
||||
$currentProfile = Get-Content $PROFILE
|
||||
@"
|
||||
(Get-Location).Path
|
||||
Set-Location $testdrive
|
||||
"@ > $PROFILE
|
||||
|
||||
try {
|
||||
$out = pwsh -workingdirectory ~ -c '(Get-Location).Path'
|
||||
$out | Should -HaveCount 2
|
||||
$out[0] | Should -BeExactly (Get-Item ~).FullName
|
||||
$out[1] | Should -BeExactly "$testdrive"
|
||||
}
|
||||
finally {
|
||||
Set-Content $PROFILE -Value $currentProfile
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue