How to re-run property evaluation in MSBuild target? -
i have custom msbuild target, partial snippet follows ..
<target name="publishhtm"> <propertygroup> <publishhtmtemplatecontents>$([system.io.file]::readalltext($(publishhtmtemplatepath)))</publishhtmtemplatecontents> <publishhtm>$(publishhtmtemplatecontents)</publishhtm> </propertygroup> <writelinestofile lines="$(publishhtm)" file="$(publishdir)\publish.htm" overwrite="true"/> </target>
this rework attempt this solution in i'm trying isolate template external file. template contains msbuild property references such $(applicationname)
. when doing described in linked solution, works fine, when loading template in string, none of these property expressions evaluated time gets file.
<span class="bannertextapplication">$(applicationname)</span>
is there msbuild expression/function can use string reevaluated given context target being invoked?
btw i'd rather not work around problem using find/replace or regex replace, , stick msbuild expression engine.
using visual studio 2012 & .net framework 4.5.
sorry not getting question awhile. thought solve problem we'll need bend msbuild in unusual way (plan today write complex inline task regex-replace in external file using msbuild properties tokens ). think can solved easier, using cdata section, valid inside property definition:
here main script:
<?xml version="1.0" encoding="utf-8"?> <project toolsversion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" defaulttargets="build"> <propertygroup> <myotherproperty>$([system.datetime]::now)</myotherproperty> <version>1.0.1b</version> <projectname>msbuild rox</projectname> <author>alexey shcherbak</author> </propertygroup> <target name="build"> <itemgroup> <propstopass include="myotherproperty=$(myotherproperty)" /> <propstopass include="version=$(version)" /> <propstopass include="projectname=$(projectname)" /> <propstopass include="author=$(author)" /> </itemgroup> <msbuild projects="transformhtml.template.proj" properties="@(propstopass)" /> </target> </project>
and here template. it's not pure html, it's still msbuild file, @ least without ugly encoding html tags in xml. it's block in cdata
<?xml version="1.0" encoding="utf-8"?> <project toolsversion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" defaulttargets="transform"> <propertygroup> <htmlproperty><![cdata[ <body> <div>$(myotherproperty)</div> <div>$(version)</div> <div>$(projectname)</div> <div>$(author)</div> </body> ]]></htmlproperty> </propertygroup> <target name="transform"> <message text="htmlproperty: $(htmlproperty)" importance="high" /> </target> </project>
maybe it's not elegant ( don't section @propstopass) it'll job. can put inline single file , don't need pass properties msbuild task. don't massive html-encoding proposed "this solution" i'd rather prefer keep html template in same script it'll transformed, in nice html format, without encoding.
single file example:
<?xml version="1.0" encoding="utf-8"?> <project toolsversion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" defaulttargets="build"> <propertygroup> <myotherproperty>$([system.datetime]::now)</myotherproperty> <version>1.0.1b</version> <projectname>msbuild rox</projectname> <author>alexey shcherbak</author> </propertygroup> <target name="build"> <propertygroup> <htmlproperty><![cdata[ <body> <div>$(myotherproperty)</div> <div>$(version)</div> <div>$(projectname)</div> <div>$(author)</div> </body> ]]></htmlproperty> </propertygroup> <message text="htmlproperty: $(htmlproperty)" importance="high" /> </target> </project>
you can download these files here
Comments
Post a Comment