MSBuild ItemGroup Include/Exclude pattern issue -
problem: itemgroups array isn't correctly build based on value passed in exclude attribute.
if run scrip creates sample file tries create array called thefiles based on include/exclude attributes, problem when exclude other hardcoded or simple property gets wrong.
the target dynamicexcludelist's incorrectly selects these files:
.\afolder\test.cs;.\afolder\test.txt
the target hardcodedexcludelist's correctly selects these files:
.\afolder\test.txt
any appreciated, driving me nuts.
(note msbuild v4)
<project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" defaulttargets="run"> <target name="run" > <calltarget targets="createsamplefiles" /> <calltarget targets="dynamicexcludelist" /> <calltarget targets="hardcodedexcludelist" /> </target> <target name="createsamplefiles" > <makedir directories="afolder" /> <writelinestofile lines="test" file="afolder\test.cs" overwrite="true" /> <writelinestofile lines="test" file="afolder\test.txt" overwrite="true" /> </target> <target name="dynamicexcludelist" > <propertygroup> <commonfileexclusion>.\directory_name_token\**\*.cs</commonfileexclusion> <finalexcludes>$(commonfileexclusion.replace('directory_name_token', 'afolder'))</finalexcludes> </propertygroup> <message text="finalexcludes: $(finalexcludes)" /> <itemgroup> <thefiles include=".\afolder\**\*;" exclude="$(finalexcludes)" /> </itemgroup> <message text="thefiles: @(thefiles)" /> </target> <target name="hardcodedexcludelist" > <propertygroup> <finalexcludes>.\afolder\**\*.cs</finalexcludes> </propertygroup> <message text="finalexcludes: $(finalexcludes)" /> <itemgroup> <thefileswithhardcodedexcludes include=".\afolder\**\*;" exclude="$(finalexcludes)" /> </itemgroup> <message text="thefileswithhardcodedexcludes: @(thefileswithhardcodedexcludes)" /> </target> </project>
this output, note differences between 'thefiles' , 'thefileswithhardcodedexcludes'
ps c:\svn\trunkdeployment\testmsbuild> msbuild .\test.build.xml microsoft (r) build engine version 4.0.30319.1 [microsoft .net framework, version 4.0.30319.1] copyright (c) microsoft corporation 2007. rights reserved. build started 8/10/2010 2:30:42 pm. project "c:\svn\trunkdeployment\testmsbuild\test.build.xml" on node 1 (default targets). dynamicexcludelist: finalexcludes: .\afolder\**\*.cs thefiles: .\afolder\test.cs;.\afolder\test.txt hardcodedexcludelist: finalexcludes: .\afolder\**\*.cs thefileswithhardcodedexcludes: .\afolder\test.txt done building project "c:\svn\trunkdeployment\testmsbuild\test.build.xml" (default targets). build succeeded. 0 warning(s) 0 error(s) time elapsed 00:00:00.06
edits
i've updated above script use createitem, there still issue when list of items exclude contains more 1 path (i.e. value of commonfileexclusion has changed):
<project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" defaulttargets="run"> <target name="run" > <calltarget targets="createsamplefiles" /> <calltarget targets="dynamicexcludelist" /> <calltarget targets="hardcodedexcludelist" /> </target> <target name="createsamplefiles" > <makedir directories="afolder" /> <writelinestofile lines="test" file="afolder\test.cs" overwrite="true" /> <writelinestofile lines="test" file="afolder\test.txt" overwrite="true" /> <writelinestofile lines="test" file="afolder\test.vb" overwrite="true" /> </target> <target name="dynamicexcludelist" > <propertygroup> <commonfileexclusion>.\directory_name_token\**\*.cs;.\directory_name_token\**\*.vb;</commonfileexclusion> <finalexcludes>$(commonfileexclusion.replace('directory_name_token', 'afolder'))</finalexcludes> </propertygroup> <message text="finalexcludes: $(finalexcludes)" /> <createitem include=".\afolder\**\*;" exclude="$(finalexcludes)"> <output taskparameter="include" itemname="thefiles"/> </createitem> <message text="thefiles: @(thefiles)" /> </target> <target name="hardcodedexcludelist" > <propertygroup> <finalexcludes>.\afolder\**\*.cs;.\afolder\**\*.vb</finalexcludes> </propertygroup> <message text="finalexcludes: $(finalexcludes)" /> <createitem include=".\afolder\**\*;" exclude="$(finalexcludes)"> <output taskparameter="include" itemname="thefileswithhardcodedexcludes"/> </createitem> <message text="thefileswithhardcodedexcludes: @(thefileswithhardcodedexcludes)" /> </target> </project>
ok, tried little , think problem comes fact use property represent scalar value multiple values. recommend batching , transforming (see http://scottlaw.knot.org/blog/?p=402 , http://msdn.microsoft.com/en-us/library/ms171476.aspx). example following code working :
<target name="dynamicexcludelist" > <itemgroup> <extensionsexcluded include="cs;vb" /> </itemgroup> <createitem include=".\afolder\**\*" exclude="@(extensionsexcluded->'.\afolder\**\*.%(identity)')"> <output taskparameter="include" itemname="thefiles"/> </createitem> <message text="thefiles: @(thefiles)" /> </target>
Comments
Post a Comment