In MSBuild, can I use the String.Replace function on a MetaData item? -
in msbuild v4 1 can use functions (like string.replace
) on properties. how can use functions on metadata?
i'd use string.replace
function below:
<target name="build"> <message text="@(files->'%(filename).replace(".config","")')" /> </target>
unfortunately outputs (not quite going for): log4net.replace(".config","");ajaxpro.replace(".config","");appsettings.replace(".config","");cachingconfiguration20.replace(".config","");cmssiteconfiguration.replace(".config","");dataproductsgraphconfiguration.replace(".config","");ajaxpro.replace(".config","");appsettings.replace(".config","");cachingconfiguration20.replace(".config","");cmssiteconfiguratio
any thoughts?
you can little bit of trickery:
$([system.string]::copy('%(filename)').replace('config',''))
basically, call static method 'copy' create new string (for reason doesn't if try $('%(filename)'.replace('.config',''))
), call replace function on string.
the full text should this:
<target name="build"> <message text="@(files->'$([system.string]::copy("%(filename)").replace(".config",""))')" /> </target>
edit: msbuild 12.0 seems have broken above method. alternative, can add new metadata entry existing files
items. perform replace while defining metadata item, can access modified value other metadata item.
e.g.
<?xml version="1.0" encoding="utf-8"?> <project toolsversion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <itemgroup> <files include="alice.jpg"/> <files include="bob.not-config.gif"/> <files include="charlie.config.txt"/> </itemgroup> <target name="build"> <itemgroup> <!-- modify existing 'files' items contain entry have done our replace. note: needs done within '<target>' (it's requirment modifying existing items --> <files> <filenamewithoutconfig>$([system.string]::copy('%(filename)').replace('.config', ''))</filenamewithoutconfig> </files> </itemgroup> <message text="@(files->'%(filenamewithoutconfig)')" importance="high" /> </target> </project>
result:
d:\temp>"c:\program files (x86)\msbuild\12.0\bin\msbuild.exe" /nologo test.xml build started 2015/02/11 11:19:10 am. project "d:\temp\test.xml" on node 1 (default targets). build: alice;bob.not-config;charlie done building project "d:\temp\test.xml" (default targets).
Comments
Post a Comment