An extension for Microsoft Visual Studio on Windows to provide an implementation of Visual Studio path macros for project batch scripts.
When writing scripts for this extension, most functions of batch will operate as normal. However, the engine provides a set of variables based on the paths to project files.
Each variable name is made up of a base variable and an optional modifier. The following variables are available:
solutionFile: the VS solution fileprojectFile: the project filefile: the script file
- no modifier: the name of the file specifed by the base variable, without the extension
WithExtension: the name of the file specifed by the base variable, with the extensionExtension: the extension of the file specifed by the base variableDirectory: the absolute path to the direcrory where the file specifed by the base variable residesFullPath: the absolute path to the file specifed by the base variable
When using a variable in a script, you must prefix it with a $ and enclose it in brackets. e.g. $(projectFileDirectory).
Expanded variables are automatically wrapped in double quotes. At this time there is no way to override this behaviour, but there may be in future versions (happy to accept contributions).
When writing scripts for this extension you must use the .batscript file extension. It is also recomended to put all your scripts in a .scripts folder in your project direcrory, but scripts anywhere in the project tree are supported, as long as they are visible to Visual Studio.
See the Implementation section below for the reasons for these suggestions.
The engine will expand variables only in the file that is run and cannot analyse any scripts called from it. Therefore, if you require looping you should do one of the following:
- Write your child scripts as normal
.bats and use the$(fileDirectory)variable to locate other scripts and run them from your main script, passing them any paths they need as parameters. - For recursive scripts that must call themselves, use the
%0batch variable, as the$(file)variable will point to the original script file with unexpanded variables.
To run a script, right click on it in the VS Solution Explorer, and find the Run script option.
There is currently no way to stop an executing script.
This engine works by taking the file that is run and expanding any variables that it finds in it. It then saves the file in the local temp data directory as a batch script and calls it. The following call paramaters are used:
UseShellExecute: falseCreateNoWindow: trueWorkingDirectory: The direcrory where the original script file resides
The standard output and error feeds are also asynchronously redirected to the Extensible batch engine pane in the VS Output window in real time.
Temporary batch files are deleted after being run.
It is recommended that before you use this extension for any production related purposes you run the example script and examine the output in order to familiarise yourself with the different variables.
My thanks to @pauer24 for their VS Namespace Fixer extension from which I have pulled a lot of the code needed to locate project and solution files. The license for this code can be found in the licenses folder.