Question

Is there anyway to modify each item in an item group? For example, given this item:

<_CustomAreas Include="..\My.Project.*\Areas\**\*.*" Condition="'$(AppBuildFolder)' == ''" />

I want to remove the "..\My.Product.* portion. Basically we have separate project containing MVC areas, and in the Package / Deployment (MSDeploy) we want to copy them into the main project. Here's where the group is used:

<FilesForPackagingFromProject Include="%(_CustomAreas.Identity)">
    <DestinationRelativePath>Areas\%(relativedir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>

$(relativedir) is coming through as "..\My.Project.Plugin1\Areas**." and it ends up in the package as ZipFileRoot\My.Project.Plugin1\Areas (The .. backs out of the hardcoded Areas, and then it just creates the folder for the plugin\areas) where I'd like it to actually all end up in ZipFileRoot\Areas.

Thanks Andy

Was it helpful?

Solution

The RegexReplace (credentials: guest/guest) task should be able to match \My.Product.* and replace with an empty string.

Something like this should work: (untested, need to verify escaping)

<RegexReplace Input="%(_CustomAreas)" Expression="\\My\.Product\..*" Replacement="" Count="-1">
    <Output ItemName="_CustomAreas" TaskParameter="Output" />
</RegexReplace>

There's a little work getting the MSBuild Community Tasks up and running, but enough good stuff in there for me to find it worth the effort.

OTHER TIPS

With MsBuild 4.0 You can use String methods directly in your script (or use inline tasks). With this option, you can edit your relativedir to delete the My.Project.* part .

You can see examples in this article : http://sedodream.com/2010/03/07/MSBuild40PropertyFunctionsPart1.aspx

Items in ItemGroups can have an Exclude attribute that allows you to specify items to leave out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top