Using MSBuild to Create Multiple Project Directories

As part of my build process in MSBuild 4.0, I get the following directory structure:

\OutDir \ProjectA \File1.dll \File2.dll \File3.exe \ProjectB \Subfolder1 File4.html \File5.dll \File6.dll \File7.exe \ProjectC \File8.dll \File9.exe 

I want to create one zip file for each \OutDir subfolder. If I do the following:

 <ItemGroup> <ZipSource Include="\OutDir\**.*" /> </ItemGroup> <MSBuild.Community.Tasks.Zip Files="@(ZipSource)" ZipFileName="OutDir\%(ZipSource.RecursiveDir)ZippedOutput.zip" WorkingDirectory="OutDir" /> 

then each subfolder is encrypted recursively, which works fine for ProjectA and ProjectC, but ProjectB ends with two zip files, one from its root level and one of its subfolders.

My other requirement is that the number of projects is unknown in the assembly file, so I cannot just create an ItemGroup and list the projects that I want to archive.

This task would be simple in NAnt through its foreach task, but how can I achieve this in MSBuild, preferably without resorting to user tasks?

+4
source share
2 answers

I came up with a workaround - a combination of the FileUnder task of the MSBuild extension package to list the ProjectX folders that I want to pin and the Exec task that calls 7Zip. The code:

 <MSBuild.ExtensionPack.FileSystem.FindUnder TaskAction="FindDirectories" Path="$(WebOutputFolder)" Recursive="False"> <Output ItemName="WebsiteFolders" TaskParameter="FoundItems" /> </MSBuild.ExtensionPack.FileSystem.FindUnder> <Exec Command="7za.exe a -r %22$(OutDir)%(WebsiteFolders.Filename)-$(Configuration)-$(AssemblyFileVersion).zip%22 % 22@ (WebsiteFolders)\*%22" /> 

So, each zip file is named after the folder from which its contents were obtained (as well as configuration and version information), so I will have the files in the folder with the output of ProjectA-Debug-0.1.2.345.zip, etc.

+3
source

Most likely, this is due to the fact that the built-in function of the .Net zip infrastructure cannot execute subfolders, only files - if your task uses this function, you are not lucky.

Also your syntax for ZipSource Include="\OutDir\**.*" little wrong, try using <ZipSource Include="\OutDir\**\*.*" .

If this does not work, try using the Zip task from Here's the doco for it ).

0
source

All Articles