Support Statement: Override a routine in authortext.gmsl
Q. How can I modify a System gmSL routine?
A. Add a gmSL block replacing the method to your translation Script as described below.
A typical gmStudio translation is directed by several things:
- Your source code
- The gmPL and gmSL commands in rule files and scripts that you integrate with your upgrade solution
- The system metalanguage files that define VB6/ASP language elements
- The system gmSL scripts that provide common dynamic processing
- The logic in the gmBasic executable
The system metalanguage files and gmSL scripts are typically pre-compiled into a system metalanguage file, VB7Lang.vbi.
You can see the system metalanguage files on the settings form in gmStudio:
One of system gmSL scripts is authortext.gmsl. This script is processed by the the system metalanguage script. vb7lang.xml:
<gmSL NameSpace="gmSL" Class="AuthorText" Source="AuthorText.gmsl" />
The script contains routines that author "boilerplate" content that cannot be generated from the VB6 source; for example configurations in the csproj file, AssemblyInfo files, resx files, and many other blocks of "boiler plate" text that are added to the translation results.
At the top of Authortext.gmsl you will find two empty routines:
void AddUserReferences() { } void AddUserCompiles() { }
These routines are called by gmBasic when it authors the .NET project file. They may be modified to add custom assembly references and code file references.
One option for doing this is to use a project-specific metalang as described here Custom VB6 Language Replacement.
A less involved option is to add a gmSL block to your translation script for example:
... <gmSL namespace="gmSL" Class="AuthorText" ><[CDATA[[ void AddUserReferences() { Write.Line("<!-- AddUserReferences here -->"); } void AddUserCompiles() { Write.Line("<!-- AddUserCompiles here -->"); } ]]></gmsl> <Compile Project="%SrcPath%" Resx="%ResxFolder%" />
This effectively overrides the default implementation with the one provided. The effect on the csproj file can be seen in this difference report:
Overriding AuthorText routines with dependencies
In many situations you may want to override AuthorText routines that have dependencies. For example lets say you want to override the ClassFile, AssemblyFile, and EndNewcProject routines. You would start by copying these methods into a text file (e.g. DCOMAuthorText.gmsl) and place it in your workspace\usr folder. Next modify your copy so that any references to symbols still in the original AuthorText.gmsl are prefixed by AuthorText (i.e. the authortext.gmsl Class name).
*****DCOMAuthorText.gmsl Write.Line("!)(!"); int StartupIsForm = AuthorText.hasStartupForm(); <== if (StartupIsForm) ***** \installdir\support\METALANG\AuthorText.gmsl Write.Line("!)(!"); int StartupIsForm = hasStartupForm(); if (StartupIsForm)
Once this is done, you can direct the transaltor to use your overrides by adding a <gmsl > command to your translation script prior to the Compile command:
<gmSL NameSpace="gmSL" Source="..\usr\DCOMAuthorText.gmsl" /> ... <Compile ...>