Sergey
Sergey

Reputation: 61

MSBuild: adding/copying empty folders via Zip/Copy task

I'm trying to create copy/zip a pre-compiled site which is contains empty folders(after pre-compilation). Looks like empty folders is not included to the list of items after CreateItem task. How I can care of empty folders?

thanks

Upvotes: 6

Views: 2650

Answers (4)

mjkwak.blanco
mjkwak.blanco

Reputation: 1

It may be a little tricky, but I think it works if all your files and folders are in a common root and you zip that root folder without using wildcards (just using '.'):

<PropertyGroup>
    <SourcePath>.\path\to\rootFolder</SourcePath>
    <FinalZipFileName>.\path\to\destination\myzip.zip</FinalZipFileName>
</PropertyGroup>

<Target Name="MyApplicationZip" >
    <Zip ZipFileName="$(FinalZipFileName)" WorkingDirectory="$(SourcePath)" Files="$(SourcePath)\." ZipLevel="9" />
</Target>

Upvotes: 0

paulj
paulj

Reputation: 11

For just copying empty folders you can use an exec task to call RoboCopy. You can specify the argument /MIR which will mirror the entire tree you are trying to copy, including empty folders.

Example:

<Exec Command="robocopy &quot;$(SourceLocation)\&quot; &quot;$(TargetLocation)\&quot; /MIR" IgnoreExitCode="true" />

Similarly, you could use an exec task to call a compression utility that has a command line interface to achieve the zip with empty folders.

Upvotes: 1

Sayed Ibrahim Hashimi
Sayed Ibrahim Hashimi

Reputation: 44322

MSBuild will not pick up empty folders when creating items. You will have to use a task (like the FindUnder task from the MSBuild Extension Pack) if you want to be able to place empty folders into an item.

Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

Upvotes: 4

Rihan Meij
Rihan Meij

Reputation: 1759

I don't feel that this is the most elegant solution, but what we have done before is, creating a folder in the solution, and a text file called placeholder.txt or something similar, and the setting the properties of the text file to be included in the build. The result is a folder where you want it containing a file that you don't want. We then delete the placeholder.txt file before we zip it up, all within the build script.

Not elegant but it does the job for our scenario.

Upvotes: 4

Related Questions