简体   繁体   中英

How to debug vbscript with Visual Studio Community (2019)

I'd like to find a free solution to debug vbscripts, and I tried Visual Studio 2019 Community Edition. I did the very basic installation with only one additional component, the Just-In-Time debugger. I ran all the following steps as administrator.

I have created the file Script2.vbs with this very simple script:

a=1
b=1/0
c=1

I started the command line (cmd.exe) and entered cscript.exe /x "C:\\...\\Script2.vbs cscript 调试 vbs

The script is executed and fails as expected at line 2 but

the problem is that the Just-In-Time debugger doesn't start.

(I expect the popup which is below "The Visual Studio Just-In-Time Debugger window appears" in this Microsoft article )

I have found in this question about the previous version of the Community Edition that there should be the option "Script", but I don't have it:

Visual Studio 社区选项调试器 jit 脚本

Note also that if I try to start the script from Visual Studio Community, the menu Debug > Start debugging is grayed out:

Visual Studio 社区开始调试变灰

My main question is:

Is the feature of debugging scripts turned off with Visual Studio Community Edition ?

(which leads to the second question: is there a solution to debug VBS scripts for free?)

You can download the VBS debugger from my OneDrive https://1drv.ms/u/s!AvqkaKIXzvDieQeOGgxLJICZ-uY?e=3r5B91

It is called scd10en.exe .

It has disappeared from MS's web site.

If you are still interested, there is a way to fix Visual Studio Community. It's likely some missing pre-requisites. Therefore you need to "Modify" the installed options and find "Script" debugging options in the Individual Components setup.

For example this is my minimum set of components.

在此处输入图片说明

peregrinus gave the right answer so I Accepted it. Here are the details :

My test was with Visual Studio Community 2019, version 16.7.7.

  1. I installed Visual Studio from scratch with only the following 3 minimal components使用 Visual Studio Community 2019 调试 VBS 的最少组件

    • Compilers, build tools, and runtimes
      • C++ CMake tools for Windows
      • MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.27)
    • Debugging and testing
      • Just-In-Time debugger
  2. I ran the VBS with the option /x to start the debugger
    CScript.exe /x Script2.vbs
    Cmd CScript.exe /x 调试 VBS

  3. A popup appears to select the Just-In-Time Debugger, I kept the options as proposed and pressed OK
    CScript /x 之后的 Visual Studio Community 2019 VBS JIT 调试器

  4. The VBS code is shown, the debugger stops at the first line of the script
    Visual Studio Community 2019 VBS JIT 调试器

  5. I can add a breakpoint at line 2, watch the variable a , and if I press Continue ( F5 ), that stops at the breakpoint, etc.
    Visual Studio Community 2019 VBS JIT 调试器、观察和断点

NB: for information, I now see the third debugging option "Script" in VS menu Tools > Options: 在此处输入图片说明

I installed Visual Studio 2019 Community Edition on a new installation of Windows 10 and experienced this same problem.

My initial installation of VS included just the ".NET desktop development" workload.

Once I installed the "Python Development" workload, the script option appeared under the Just-In-Time debugging options. No other changes were required.

Visual Studio 安装程序选项

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM