@@ -557,6 +557,14 @@ module DotnetCli =
557557 let argString = String.Join( " " , args)
558558 logger.Debug( $" Running `dotnet {argString}`" )
559559
560+ let getEnv enableTestHostDebugger =
561+ let parentEnv = Node.Api.`` process `` .env
562+ let childEnv = parentEnv
563+ //NOTE: Important to include VSTEST_HOST_DEBUG=0 when not debugging to remove stale values
564+ // that may cause the debugger to wait and hang
565+ childEnv?VSTEST_ HOST_ DEBUG <- ( if enableTestHostDebugger then 1 else 0 )
566+ childEnv |> box |> Some
567+
560568 match shouldDebug with
561569 | Debug ->
562570 let mutable isDebuggerStarted = false
@@ -571,20 +579,8 @@ module DotnetCli =
571579 launchDebugger processId
572580 isDebuggerStarted <- true
573581
574- let env =
575- let parentEnv = Node.Api.`` process `` .env
576- let childEnv = parentEnv
577- childEnv?VSTEST_ HOST_ DEBUG <- 1
578- childEnv |> box |> Some
579-
580- Process.execWithCancel " dotnet" ( ResizeArray( args)) env tryLaunchDebugger cancellationToken
581- | NoDebug ->
582- let env =
583- let staleOverrides = {| VSTEST_ HOST_ DEBUG = 0 |}
584- staleOverrides |> box |> Some
585-
586- Process.execWithCancel " dotnet" ( ResizeArray( args)) env ignore cancellationToken
587-
582+ Process.execWithCancel " dotnet" ( ResizeArray( args)) ( getEnv true ) tryLaunchDebugger cancellationToken
583+ | NoDebug -> Process.execWithCancel " dotnet" ( ResizeArray( args)) ( getEnv false ) ignore cancellationToken
588584
589585 type TrxPath = string
590586 type ConsoleOutput = string
0 commit comments