Readme.mdSharp-ToolRunner (STR) is a Visual Studio add-in that allows you to transform one file type into another file; in Visual Studio parlance it's a "custom tool" sometimes called a "single file generator". Rather than creating a custom tool for each type of transformer Sharp-ToolRunner allows you to use external programs to do the transformation as long as that program is command line accessible. Before I continue ...There are other tools that do similar things and if you're interest is in ".less -> .css", or ".md -> .html" processing you probably want to use one of those tools. STR does not add editing features or syntax highlighting, it does not even perform the compiling, translation, or transforms on your files itself. STR calls the compiler or translator in the background when you save your file. ".less", and ".md" files are just examples, you can run any application or script that has a command line interface that allows you to perform the actions you require. Normally you will want to take the file you're editing in Visual Studio, pass it through a transformation, and then have Visual Studio save the result as a child file of the source file in your project. If need be you can run multiple commands against the source file, or pipe the results from one program to another until you have the created the result you want. STR does not include the ".less", ".md", or any other translators/compilers within it's installer. Any programs or scripts you required to perform the actions you require must already be installed and working properly on your system before STR can make use of them. Configuration filesSTR works by reading a configuration file which you can easily extend to include your own tools. It processes target (input) files by looking up their extension, or file name. The configuration file is written in JSON to make for easy editing. The entry above is for less and should be read something like this:
Several things to note.
AdditionallyYou can use file names in the "Id" member of a rule, this allows for configurations for specific files. In this example any files named "SpecialFile.less" would use this configuration and pass the ".xcss" extension (rather than ".css") back to Visual Studio. There are several other "tricks", and commands you can use which I will document later. Configuration file locationYou can have multiple configuration files, there locations can be:
The configuration files are read first to last creating a list of rules with the highest precedence being given to the rules "closest" to the target file. So, if you have a rule for ".md" in a configuration file in the target files directory it will be chosen instead of any rule defined in any other configuration file. The name of the configuration file is always tool-runner.cfg.json. Registering Sharp-ToolRunner as a Custom Tool for your filesBefore you can use STR you must associate it as a "Custom Tool" with the files you wish to work with, you do this with the files properties. Right click on the file in Solution Explorer and select "Properties". On the files property page add "SharpToolRunner" as the "Custom Tool". Note. If there is already an entry from some tool other than SharpToolRunner you probably do not want to replace it. If you do decide to replace it make sure you know what you're doing, Visual Studio can sometimes be very opaque about what configuration options it sets and it can be difficult getting back to where you started. Configuration file entriesCurrently there are several entries in the configuration file. Check the sharp-toolrunner.cfg.json file for the latest configuration as these examples may be out of date. .g4 (Antlr4 compiler)Antlr4 generates more than one output file which is handled by this configuration. Before I explain how that works note that (1) this configuration produces C# from the grammar file, (2) java.exe must be in the path, and (2) "antlr-4.5.3-complete.jar" must be given a full path following the "-jar" (the only way I was able to get java.exe to find the antlr4 jar file, note: I speak very little java and there may be a better way to do this). (3) you can put "antlr-4.5.3-complete.jar" anywhere you want, but the path must be set correctly, this is setup for my machine. For an Antlr4 grammar file named "parameters.g4":
.less (less compiler) .md (markdown via marked, to html file) This translate markdown (.md) to html. There a several things to note about this entry.
The "replace" command takes two arguments, "--content--" is the text to replace in the file referenced by the second argument. This text ("--content--") will be replaced by the output of the first command (the "marked" compiler). The second argument (file name) starts with ".assets:" which indicates STR should find it in the ".Assets" folder of the STR installation directory. You can customize the output by changing the .html file, add a reference to your own html source file somewhere in the file system. An absolute file name ("c:\files\some-file.html") will be searched for as is; a file name or name name with a partial path will be searched for relative to the input file's location. .ps1 (powershell) Note "ReadStdOut" is set to true; .btm (jpsoft's 'TCC' and "Take Command" processors) .ts (typescript) License |