VS2013:即使从IDE运行,“VSP2340:环境变量也没有正确设置”
我正在从Visual Studio 2013中分析一个C#程序。我转到Analyze – > Performance and Diagnostics来启动向导。 它给了我一个分析方法的选择。 如果我选择默认的CPU采样,那么分析工作,我可以看到结果。 但是,如果我选择第三个选项,即.NET内存分配,那么在我的应用程序完成后,我会在Visual Studio输出窗口中看到空结果和此错误:
VSP2340: Environment variables were not properly set during profiling run and managed symbols may not resolve. Please use vsperfclrenv before profiling
我在网上看到的所有文档都表明, vsperfclrenv
用于独立分析器,直接从Visual Studio运行分析器时不需要。 但是,为了安全起见,我尝试从命令提示符窗口设置必要的环境变量,然后直接从该窗口运行IDE,以便它获取环境:
C: cd "\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Performance Tools\x64" vsperfclrenv /samplegclife /tracegclife /globalsamplegclife /globaltracegclife "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"
然后我像以前一样去了Visual Studio里面的性能向导。 但结果是一样的; 我仍然看到VSP2340试图分析结果。 我究竟做错了什么?
我注意到该向导有四种分析可供选择:CPU采样,检测,内存分配和资源争用。 这与vsperfclrenv
提供的选项并不完全匹配,后者仅讨论了采样和跟踪分析(每个应用程序与服务变体;我的程序是应用程序而不是服务,但我启用了所有选项以确保) 。
可能是内存分配分析需要一些额外的环境变量吗? 或者是关于vsperfclrenv
误导的Visual Studio消息?
这可能与管理权限有关。 就我而言,我知道两个解决方法:
- 以具有真实管理员权限的用户身份运行Visual Studio。
- 使用[开始 – > Microsoft Visual Studio 2012 – > Visual Studio工具 – >] VS2012开发人员命令提示符 – >以管理员身份运行。 在命令提示符下,
vsperfclrenv /samplegclife
。 窗口标题从Administrator: Developer Command Prompt for VS2012
为Administrator: VSPerf Sampling Attaching and Allocation Profiling with objects lifetime 'ON'
。 然后"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe"
。
第二种方法看起来就像原始海报所做的那样,除了使用开发人员命令提示符以管理员身份运行而不是普通的cmd.exe窗口。 对我来说,当我不以管理员身份运行时,我收到VSP2340错误。
我遇到了非常相似的症状,环境略有不同:Windows 7,作为普通用户(不在本地Administrators组中),从“开始”菜单启动Visual Studio 2012,使用Avecto Defendpoint为Visual Studio可执行文件授予提升权限,CPU分析产生了正常结果,但.NET内存分配采样结果为空白。 输出窗口说:
Profiling started. Profiling process ID #### (xxxx). Process ID #### has exited. Data written to C:\path\to\solution\xxxxyymmdd.vsp. Profiling finished. VSP2340: Environment variables were not properly set during profiling run and managed symbols may not resolve. Please use vsperfclrenv before profiling. Profiling complete.
对于CPU性能分析运行,而不是VSP2340,我得到Loaded symbols for [full/path/to/dll]
的Loaded symbols for [full/path/to/dll]
的长列表
您是否尝试运行Visual Studio命令提示符(以管理员身份)并运行命令vsperfclrenv / globalsampleon? 在thad之后,您可能需要重新启动。