@@ -1040,26 +1040,28 @@ public async Task ExecuteScriptWithArgsAsync(string script, string arguments = n
1040
1040
1041
1041
if ( arguments != null )
1042
1042
{
1043
- // Need to determine If the script string is a path to a script file.
1044
- string scriptAbsPath = string . Empty ;
1045
- try
1046
- {
1047
- // Assume we can only debug scripts from the FileSystem provider
1048
- string workingDir = ( await ExecuteCommandAsync < PathInfo > (
1049
- new PSCommand ( )
1050
- . AddCommand ( "Microsoft.PowerShell.Management\\ Get-Location" )
1051
- . AddParameter ( "PSProvider" , "FileSystem" ) ,
1052
- sendOutputToHost : false ,
1053
- sendErrorToHost : false ) . ConfigureAwait ( false ) )
1054
- . FirstOrDefault ( )
1055
- . ProviderPath ;
1056
-
1057
- workingDir = workingDir . TrimEnd ( Path . DirectorySeparatorChar ) ;
1058
- scriptAbsPath = workingDir + Path . DirectorySeparatorChar + script ;
1059
- }
1060
- catch ( System . Management . Automation . DriveNotFoundException e )
1043
+ // Add CWD from PowerShell if not an absolute path
1044
+ if ( ! Path . IsPathRooted ( script ) )
1061
1045
{
1062
- this . logger . LogHandledException ( "Could not determine current filesystem location" , e ) ;
1046
+ try
1047
+ {
1048
+ // Assume we can only debug scripts from the FileSystem provider
1049
+ string workingDir = ( await ExecuteCommandAsync < PathInfo > (
1050
+ new PSCommand ( )
1051
+ . AddCommand ( "Microsoft.PowerShell.Management\\ Get-Location" )
1052
+ . AddParameter ( "PSProvider" , "FileSystem" ) ,
1053
+ sendOutputToHost : false ,
1054
+ sendErrorToHost : false ) . ConfigureAwait ( false ) )
1055
+ . FirstOrDefault ( )
1056
+ . ProviderPath ;
1057
+
1058
+ this . logger . LogTrace ( $ "Prepending working directory { workingDir } to script path { script } ") ;
1059
+ script = Path . Combine ( workingDir , script ) ;
1060
+ }
1061
+ catch ( System . Management . Automation . DriveNotFoundException e )
1062
+ {
1063
+ this . logger . LogHandledException ( "Could not determine current filesystem location" , e ) ;
1064
+ }
1063
1065
}
1064
1066
1065
1067
var strBld = new StringBuilder ( ) ;
@@ -1071,7 +1073,7 @@ public async Task ExecuteScriptWithArgsAsync(string script, string arguments = n
1071
1073
// If the provided path is already quoted, then File.Exists will not find it.
1072
1074
// This keeps us from quoting an already quoted path.
1073
1075
// Related to issue #123.
1074
- if ( File . Exists ( script ) || File . Exists ( scriptAbsPath ) )
1076
+ if ( File . Exists ( script ) )
1075
1077
{
1076
1078
// Dot-source the launched script path and single quote the path in case it includes
1077
1079
strBld . Append ( ". " ) . Append ( QuoteEscapeString ( script ) ) ;
0 commit comments