Simple project type that supports .js and .vbs files; can run and debug them using cscript.exe
.
- File globbing (project automatically includes *.js and *.vbs under the project cone)
- Editing the project file without unloading the project (right click on the project node -
Edit
) - Project handles own reload without the solution doing a full reload when the project file changes on disk
- Custom properties
- Custom item type - project defines
Script
item type to include *.js and *.vbs files - Custom debug launch provider using custom properties to invoke
cscript.exe
and run the script file - Run from command line using the same parameters defined above via msbuild target:
msbuild /t:run
- Open
WindowsScript.sln
in Visual Studio 2017 and use Ctrl + F5 to run it. This will open the Experimental instance of Visual Studio - From the main menu,
File
->New Project
, selectWindowsScript
->Windows Script Project
and pressOK
. This will create a new project that contains aStart.js
file - In the generated project, insert a breakpoint on the 2nd line of
Start.js
- Press F5 - this will start the debugger; it will stop at the breakpoint
- Switch to the
cscript
window - the default implementation displays information about the execution context (which script is running, current directory, arguments)
The sample doesn't currently provide any item templates. To create new files, you can:
- copy-paste the default
Start.js
- create new script files (.vbs or .js) in Windows Explorer; the project includes automatically all *.js and *.vbs located under the project cone
Project uses a custom property StartItem
to specify which script file to run. The default value is Start.js
.
- Open the Property Pages dialog (right click on the project node ->
Properties
) - Set the value of
Start Item
property (located underCommon Properties
->General
) to specify the file you would like to run (e.g.Foo.js
)
This value gets persisted in the project file:
<StartItem>Foo.js</StartItem>
Project supports a few additional properties to control the script execution.
They can be set from the project properties dialog (Configuration Properties
-> Debugging
-> Script Debugger
) and get persisted in the .user file (next to the project).
Command
(persisted asRunCommand
) - specifies which tool to invoke to run the script; by default it usescscript.exe
but you can set it towscript.exe
(offered conveniently as a predefined value when you expand the drop down)Command Arguments
(persisted asRunCommandArguments
) - specifies additional arguments to pass to the script; by default it is emptyWorking Directory
(persisted asRunWorkingDirectory
) - specifies the working directory for the script; by default it is the project folder
-
Default values are defined in the .props file. This allows them to be used from msbuild when the value is not specified.
-
.user
file is imported in .targets for consumption by msbuild<Import Project="$(MSBuildProjectFullPath).user" Condition="Exists('$(MSBuildProjectFullPath).user')" />
These properties are consumed in 2 different places:
- Debug Launch Provider (F5 and Ctrl F5 from Visual Studio) - see
ScriptDebuggerLaunchProvider.cs
- The
Run
Target - that can be used from MSBuild - seeCustomProject.targets
usingMSBuild /t:Run