@@ -255,22 +255,9 @@ protected async Task HandleLaunchRequest(
255
255
this . RegisterEventHandlers ( ) ;
256
256
257
257
// Set the working directory for the PowerShell runspace to the cwd passed in via launch.json.
258
- // In case that is null, use the the folder of the script to be executed. If the resulting
259
- // working dir path is a file path then extract the directory and use that.
260
- string workingDir =
261
- launchParams . Cwd ??
262
- launchParams . Script ??
263
- #pragma warning disable 618
264
- launchParams . Program ;
265
- #pragma warning restore 618
266
-
267
- // When debugging an "untitled" (unsaved) file - the working dir can't be derived
268
- // from the Script path. OTOH, if the launch params specifies a Cwd, use it.
269
- if ( ScriptFile . IsUntitledPath ( workingDir ) && string . IsNullOrEmpty ( launchParams . Cwd ) )
270
- {
271
- workingDir = null ;
272
- }
258
+ string workingDir = launchParams . Cwd ;
273
259
260
+ // Assuming we have a specified working dir, unescape the path and verify it.
274
261
if ( ! string . IsNullOrEmpty ( workingDir ) )
275
262
{
276
263
workingDir = PowerShellContext . UnescapePath ( workingDir ) ;
@@ -289,18 +276,28 @@ protected async Task HandleLaunchRequest(
289
276
}
290
277
}
291
278
292
- if ( string . IsNullOrEmpty ( workingDir ) )
279
+ // A null or empty string value for CWD is an indicator to NOT change the working directory
280
+ // but only if we are debugging in the integrated console where there is an existing cwd.
281
+ // However, if we are running in a temporary integrated console, there is no pre-existing
282
+ // cwd, so fall through to the "else if: where we set a working directory.
283
+ if ( string . IsNullOrEmpty ( workingDir ) && ! launchParams . CreateTemporaryIntegratedConsole )
293
284
{
285
+ Logger . Write ( LogLevel . Verbose , "Launch config requested working dir not be changed/set" ) ;
286
+ }
287
+ else if ( this . editorSession . PowerShellContext . CurrentRunspace . Location == RunspaceLocation . Local &&
288
+ ! this . editorSession . DebugService . IsDebuggerStopped )
289
+ {
290
+ // If we have no working dir by this point, pick some reasonable default.
291
+ if ( string . IsNullOrEmpty ( workingDir ) )
292
+ {
294
293
#if CoreCLR
295
- workingDir = AppContext . BaseDirectory ;
294
+ //TODO: RKH 2018-06-26 .NET standard 2.0 has added Environment.CurrentDirectory - let's use it.
295
+ workingDir = AppContext . BaseDirectory ;
296
296
#else
297
- workingDir = Environment . CurrentDirectory ;
297
+ workingDir = Environment . CurrentDirectory ;
298
298
#endif
299
- }
299
+ }
300
300
301
- if ( this . editorSession . PowerShellContext . CurrentRunspace . Location == RunspaceLocation . Local &&
302
- ! this . editorSession . DebugService . IsDebuggerStopped )
303
- {
304
301
await editorSession . PowerShellContext . SetWorkingDirectory ( workingDir , isPathAlreadyEscaped : false ) ;
305
302
Logger . Write ( LogLevel . Verbose , "Working dir set to: " + workingDir ) ;
306
303
}
@@ -316,7 +313,7 @@ protected async Task HandleLaunchRequest(
316
313
// Store the launch parameters so that they can be used later
317
314
this . noDebug = launchParams . NoDebug ;
318
315
#pragma warning disable 618
319
- this . scriptToLaunch = launchParams . Script ?? launchParams . Program ;
316
+ this . scriptToLaunch = launchParams . Script ;
320
317
#pragma warning restore 618
321
318
this . arguments = arguments ;
322
319
this . IsUsingTempIntegratedConsole = launchParams . CreateTemporaryIntegratedConsole ;
0 commit comments