Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Visual Studio 2013的Powershell控制台中显示局部变量?_C#_Visual Studio_Debugging_Powershell - Fatal编程技术网

C# 如何在Visual Studio 2013的Powershell控制台中显示局部变量?

C# 如何在Visual Studio 2013的Powershell控制台中显示局部变量?,c#,visual-studio,debugging,powershell,C#,Visual Studio,Debugging,Powershell,在Visual Studio 2013的调试过程中(.NET应用程序)如何在Powershell控制台中显示已调试的.NET应用程序的本地变量?如果您正在Powershell命令提示符中调试,请使用以下命令: 控制台: PS C:\Users\******\Desktop> Set-PSBreakpoint -script ".\1.ps1" -line 4 #setting breakpoint ID Script Line Command

在Visual Studio 2013的调试过程中(.NET应用程序)如何在Powershell控制台中显示已调试的.NET应用程序的本地变量?

如果您正在Powershell命令提示符中调试,请使用以下命令:

控制台:

PS C:\Users\******\Desktop> Set-PSBreakpoint -script ".\1.ps1" -line 4 #setting breakpoint

  ID Script            Line Command           Variable         Action
  -- ------            ---- -------           --------         ------
   0 1.ps1                4


PS C:\Users\******\Desktop> .\1.ps1
Step 1 done
Entering debug mode. Use h or ? for help.

Hit Line breakpoint on 'C:\Users\******\Desktop\1.ps1:4'

At C:\Users\******\Desktop\1.ps1:4 char:1
+ $c = "3"
+ ~~~~~~~~
[DBG]: PS C:\Users\******\Desktop>> $a #printing local variable value
2
[DBG]: PS C:\Users\******\Desktop>>
文件“1.ps1”如下所示:

$a = "2"
$b = "3"
Write-Host "Step 1 done"
$c = "3" #putting breakpoint here
$d = "4"
Write-Host "Step 2 done"
$e = "5"
$f = "6"
Write-Host "Step 3 done"

如果您使用的是powershell ise,则只需在console中写入变量名($a),它就会打印值。

如果您使用的是VS 2013而不是powershell ise,则另一种方法是在Visual Studio中集成PS命令、控制台和单元测试

在“包管理器控制台”中执行命令:

$dte.Debugger.CurrentStackFrame.Locals
该命令显示局部变量列表(包括名称):


下一步,要获取局部变量的值

我的意思是在调试c#程序时,如何从“PowerShell交互窗口”访问已调试的.NET进程的局部变量?例如,我可以通过变量$dteI访问VS,但我不明白您想要实现什么。您有一个要使用Powershell访问的.NET进程?您可以参考添加类型-路径“E:\myLibrary.dll”,然后创建像$myObject=New Object“myLibraryObject”这样的对象,并在Powershell控制台中访问这些对象。我想通过VS Powershell选项卡在VS中调试期间打印现有的.NET对象。例如,它将允许打印带有过滤器或其他高级内容的列表。
Name         : this
Type         : csharp_tips.PowerShellInDebuggerSamples
DataMembers  : System.__ComObject
Value        : {csharp_tips.PowerShellInDebuggerSamples}
IsValidValue : True
DTE          : System.__ComObject
Parent       : System.__ComObject
Collection   : System.__ComObject

Name         : doubleArray
Type         : double[]
DataMembers  : System.__ComObject
Value        : {double[3]}
IsValidValue : True
DTE          : System.__ComObject
Parent       : System.__ComObject
Collection   : System.__ComObject