|
NRecoTransform
Build Time Transformations in context of NReco
IntroductionModel transformation can be performed either on build or run time (compilation or interpretation). Build time transformations are less restrictive: nothing special is needed at run time (so huge amount of existing components could be reused without any adaptation) and usual build tools could be used for performing transformations. But in real life build-time transformation processor should meet specific functional and non-functional requirements:
Transform ToolRules are usual project XML-files. Only convention is to start their names with '@' char (like @addConnectionString.xml). Each file may contain more than one rule (see examples), XInclude instructions may be used inside rule XML. Main features:
Example: NReco.Transform.Tool.exe -w true -i true -b ./ See also transform tool usage sample. Text Modification RuleThis rule used for changing existing text files (from 'Hello World' example, @appConfig.xml): <text-insert file="NReco.Examples.Hello.exe.config" start="<configuration>"> <![CDATA[ <!-- my comment --> ]]> </text-insert> <text-replace file="NReco.Examples.Hello.exe.config" regex="-- my comment">-- my replaced comment</text-replace> <text-replace file="NReco.Examples.Hello.exe.config" start="<!-- my" end="comment"> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="config/variable_Name.txt" /> </text-replace> Note that if 'file' attribute is optional; when it is not specified target file is calculated from rule file name (just name without '@' suffix char). This rule is useful in cases when the same text file used in many projects and with small modifications. XML Modification Rule<xml-insert file="Web.config" xpath="/configuration/connectionStrings"> <add name="mainDb" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=mainDb.mdf;User Instance=True"/> </xml-insert> <xml-remove file="Web.config" xpath="/configuration/configSections"/> <xml-replace file="Web.config" xpath="/configuration/nreco.converters/converter[position()=1]"> </xml-replace> XSL Transform RuleXSL transformation rule can be used for generating files by XML models (from 'Hello World' example, @modelA_transform.xml): <xsl-transform> <xml file="config/modelA.xml"/> <xsl file="config/xsl/choose.xsl"/> <result file="config/modelA_transformed.xml.config"/> </xsl-transform> Multiple files generation using one rule is also possible: <xsl-transform> <xml file="config/layoutModels.xml"/> <xsl file="config/xsl/aspnet-ascx-models.xsl"/> <result> <file xpath="/files/file"> <name xpath="@name"/> <content xpath="content"/> </file> </result> </xsl-transform> In this sample amount of files is determined by /files/file xpath expression; file name and content is also determined by xpath-expressions. Important notes:
|
Sign in to add a comment